Cannot evaluate expression because a thread is stopped at a point where garbage collection is im
Hi.
I have found an error in a Windows Form. I have a private property List<Person> = new List<Person>(). Using the debugger I call the constructor of the Form. When the debugger passes over List appears the following error:
Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized.
I don′t know what′s the problem.
Thanks.
Try setting the build mode to Debug if you're in release mode. But it's more likely that the problem is that you simply shouldn't call the form's constructor from the debugger. Instead, let it be called in the normal execution of the program and put a breakpoint at the beginning of it.
Hi, blue
Have you tried volatile keywords before that variable?
Fields that are declared volatile are not subject to compiler optimizations that assume access by a single thread. This ensures that the most up-to-date value is present in the field at all times.
If it doesn't help, please give us more information in your code. (it seems you've used multithreading) so that we can tell where exactly the flaw is.
Thanks
Sorry by the delay.
I try again using volatile but the same error appears. I declare lists like "private volatile List<Object> xxx = new List<Object>". I don′t know if I′m doing it well.
Following I add all my code:
using
System; using
System.Collections.Generic; using
System.ComponentModel; using
System.Data; using
System.Drawing; using
System.Text; using
System.Windows.Forms; using
Basket.EstadisticasWS; namespace
Estadistica {
public partial class MenuEstadisticas : Form {
private List<Equipo> equipos = new List<Equipo>(); private List<Jugador> jugadores = new List<Jugador>(); private GestorBD gestBD = new GestorBD(); public MenuEstadisticas() {
InitializeComponent();
this.Visible = true; this.btnClasificacion.Enabled = false; this.btnEquipoRival.Enabled = false; this.btnLideres.Enabled = false; this.btnPlantilla.Enabled = false; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //Codigo del servicio web Basket.EstadisticasWS.
Service ws = new Basket.EstadisticasWS.Service(); Basket.EstadisticasWS.
Equipo[] eq = ws.getEquipos(); Basket.EstadisticasWS.
Jugador[] jug = ws.getJugadores(); if ((eq.Length == 0) && (jug.Length == 0)) {
try {
this.gestBD.Conectar(); this.equipos = this.gestBD.RecuperarEquipos(); this.jugadores = this.gestBD.RecuperarJugadores(); this.gestBD.Desconectar(); }
catch (Exception ex) {
}
}
else {
for (int i = 0; i < eq.Length; i++) {
string Nombre = eq
.Nombre; int PartidosJugados = eq
.PartidosJugados; int PartidosGanados = eq
.PartidosGanados; int PartidosPerdidos = eq
.PartidosPerdidos; int PuntosFavor = eq
.PuntosFavor; int PuntosContra = eq
.PuntosContra; double PuntosAnotados = eq
.PuntosAnotados; double PuntosRecibidos = eq
.PuntosRecibidos; double TriplesConvertidos = eq
.TriplesConvertidos; double TriplesIntentados = eq
.TriplesIntentados; string PorcentajeTirosLibres = eq
.PorcentajeTirosLibres; double DosConvertidos = eq
.DosConvertidos; double DosIntentados = eq
.DosIntentados; string PorcentajeDos = eq
.PorcentajeDos; double LibresConvertidos = eq
.LibresConvertidos; double LibresIntentados = eq
.LibresIntentados; string PorcentajeTriples = eq
.PorcentajeTriples; double RebotesDefensivos = eq
.RebotesDefensivos; double RebotesOfensivos = eq
.RebotesOfensivos; double RebotesTotales = eq
.RebotesTotales; double Asistencias = eq
.Asistencias; double Recuperaciones = eq
.Recuperaciones; double Perdidas = eq
.Perdidas; double TaponesEfectuados = eq
.TaponesEfectuados; double TaponesRecibidos = eq
.TaponesRecibidos; double Mates = eq
.Mates; double Faltas = eq
.Faltas; double FaltasRecibidas = eq
.FaltasRecibidas; double Valoracion = eq
.Valoracion; double PuntosAnotadosPlayoff = eq
.PuntosAnotadosPlayoff; double PuntosRecibidosPlayoff = eq
.PuntosRecibidosPlayoff; double TriplesConvertidosPlayoff = eq
.TriplesConvertidosPlayoff; double TriplesIntentadosPlayoff = eq
.TriplesIntentadosPlayoff; string PorcentajeTriplesPlayoff = eq
.PorcentajeTriplesPlayoff; double DosConvertidosPlayoff = eq
.DosConvertidosPlayoff; double DosIntentadosPlayoff = eq
.DosIntentadosPlayoff; string PorcentajeDosPlayoff = eq
.PorcentajeDosPlayoff; double LibresConvertidosPlayoff = eq
.LibresConvertidosPlayoff; double LibresIntentadosPlayoff = eq
.LibresIntentadosPlayoff; string PorcentajeTirosLibresPlayoff = eq
.PorcentajeTirosLibresPlayoff; double RebotesOfensivosPlayoff = eq
.RebotesOfensivosPlayoff; double RebotesDefensivosPlayoff = eq
.RebotesDefensivosPlayoff; double RebotesTotalesPlayoff = eq
.RebotesTotalesPlayoff; double AsistenciasPlayoff = eq
.AsistenciasPlayoff; double RecuperacionesPlayoff = eq
.RecuperacionesPlayoff; double PerdidasPlayoff = eq
.PerdidasPlayoff; double TaponesEfectuadosPlayoff = eq
.TaponesEfectuadosPlayoff; double TaponesRecibidosPlayoff = eq
.TaponesRecibidosPlayoff; double MatesPlayoff = eq
.MatesPlayoff; double FaltasPlayoff = eq
.FaltasPlayoff; double FaltasRecibidasPlayoff = eq
.FaltasRecibidasPlayoff; double ValoracionPlayoff = eq
.ValoracionPlayoff; this.equipos.Add(new Equipo(Nombre, PartidosGanados, PartidosJugados, PartidosPerdidos, PuntosContra, PuntosFavor, PuntosAnotados, PuntosRecibidos, TriplesConvertidos, TriplesIntentados, PorcentajeTriples, DosConvertidos, DosIntentados, PorcentajeDos, LibresConvertidos, LibresIntentados, PorcentajeTirosLibres, RebotesOfensivos, RebotesDefensivos, RebotesTotales, Asistencias, Recuperaciones, Perdidas, TaponesEfectuados, TaponesRecibidos, Mates, Faltas, FaltasRecibidas, Valoracion, PuntosAnotadosPlayoff, PuntosRecibidosPlayoff, TriplesConvertidosPlayoff, TriplesIntentadosPlayoff, PorcentajeTriplesPlayoff, DosConvertidosPlayoff, DosIntentadosPlayoff, PorcentajeDosPlayoff, LibresConvertidosPlayoff, LibresIntentadosPlayoff, PorcentajeTirosLibresPlayoff, RebotesOfensivosPlayoff, RebotesDefensivosPlayoff, RebotesTotalesPlayoff, AsistenciasPlayoff, RecuperacionesPlayoff, PerdidasPlayoff, TaponesEfectuadosPlayoff, TaponesRecibidosPlayoff, MatesPlayoff, FaltasPlayoff, FaltasRecibidasPlayoff, ValoracionPlayoff)); }
for (int i = 0; i < jug.Length; i++) {
string Equipo = jug
.Equipo; string Nombre = jug
.Nombre; int PartidosJugados = jug
.PartidosJugados; string Minutos = jug
.Minutos; int PartidosTitular = jug
.PartidosTitular; double Puntos = jug
.Puntos; double TriplesConvertidos = jug
.TriplesConvertidos; double TriplesIntentados = jug
.TriplesIntentados; string PorcentajeTriples = jug
.PorcentajeTriples; double DosConvertidos = jug
.DosConvertidos; double DosIntentados = jug
.DosIntentados; string PorcentajeDos = jug
.PorcentajeDos; double LibresConvertidos = jug
.LibresConvertidos; double LibresIntentados = jug
.LibresIntentados; string PorcentajeTirosLibres = jug
.PorcentajeTirosLibres; double RebotesOfensivos = jug
.RebotesOfensivos; double RebotesDefensivos = jug
.RebotesDefensivos; double RebotesTotales = jug
.RebotesTotales; double Asistencias = jug
.Asistencias; double Recuperaciones = jug
.Recuperaciones; double Perdidas = jug
.Perdidas; double Tapones = jug
.Tapones; double TaponesRecibidos = jug
.TaponesRecibidos; double Mates = jug
.Mates; double FaltasPersonales = jug
.FaltasPersonales; double FaltasRecibidas = jug
.FaltasRecibidas; double Valoracion = jug
.Valoracion; int PartidosJugadosPlayoff = jug
.PartidosJugadosPlayoff; string MinutosPlayoff = jug
.MinutosPlayoff; int PartidosTitularPlayoff = jug
.PartidosTitularPlayoff; double PuntosPlayoff = jug
.PuntosPlayoff; double TriplesConvertidosPlayoff = jug
.TriplesConvertidosPlayoff; double TriplesIntentadosPlayoff = jug
.TriplesIntentadosPlayoff; string PorcentajeTriplesPlayoff = jug
.PorcentajeTriplesPlayoff; double DosConvertidosPlayoff = jug
.DosConvertidosPlayoff; double DosIntentadosPlayoff = jug
.DosIntentadosPlayoff; string PorcentajeDosPlayoff = jug
.PorcentajeDosPlayoff; double LibresConvertidosPlayoff = jug
.LibresConvertidosPlayoff; double LibresIntentadosPlayoff = jug
.LibresIntentadosPlayoff; string PorcentajeTirosLibresPlayoff = jug
.PorcentajeTirosLibresPlayoff; double RebotesOfensivosPlayoff = jug
.RebotesOfensivosPlayoff; double RebotesDefensivosPlayoff = jug
.RebotesDefensivosPlayoff; double RebotesTotalesPlayoff = jug
.RebotesTotalesPlayoff; double AsistenciasPlayoff = jug
.AsistenciasPlayoff; double RecuperacionesPlayoff = jug
.RecuperacionesPlayoff; double PerdidasPlayoff = jug
.PerdidasPlayoff; double TaponesPlayoff = jug
.TaponesPlayoff; double TaponesRecibidosPlayoff = jug
.TaponesRecibidosPlayoff; double MatesPlayoff = jug
.MatesPlayoff; double FaltasPersonalesPlayoff = jug
.FaltasPersonalesPlayoff; double FaltasRecibidasPlayoff = jug
.FaltasRecibidasPlayoff; double ValoracionPlayoff = jug
.ValoracionPlayoff; this.jugadores.Add(new Jugador(Equipo, Nombre, PartidosJugados, Minutos, PartidosTitular, Puntos, TriplesConvertidos, TriplesIntentados, PorcentajeTriples, DosConvertidos, DosIntentados, PorcentajeDos, LibresConvertidos, LibresIntentados, PorcentajeTirosLibres, RebotesOfensivos, RebotesDefensivos, RebotesTotales, Asistencias, Recuperaciones, Perdidas, Tapones, TaponesRecibidos, Mates, FaltasPersonales, FaltasRecibidas, Valoracion, PartidosJugadosPlayoff, MinutosPlayoff, PartidosTitularPlayoff, PuntosPlayoff, TriplesConvertidosPlayoff, TriplesIntentadosPlayoff, PorcentajeTriplesPlayoff, DosConvertidosPlayoff, DosIntentadosPlayoff, PorcentajeDosPlayoff, LibresConvertidosPlayoff, LibresIntentadosPlayoff, PorcentajeTirosLibresPlayoff, RebotesOfensivosPlayoff, RebotesDefensivosPlayoff, RebotesTotalesPlayoff, AsistenciasPlayoff, RecuperacionesPlayoff, PerdidasPlayoff, TaponesPlayoff, TaponesRecibidosPlayoff, MatesPlayoff, FaltasPersonalesPlayoff, FaltasRecibidasPlayoff, ValoracionPlayoff)); }
}
SortedList<string, Equipo> listaOrdenada = new SortedList<string, Equipo>(); for (int i = 0; i < this.equipos.Count; i++) {
listaOrdenada.Add(
this.equipos
.getNombre(), this.equipos
); }
foreach (KeyValuePair<string, Equipo> item in listaOrdenada) {
this.comboEquipos.Items.Add(item.Key); }
}
First I try to fill those lists using a Web Service. If there is no connection I fill them using a database.
The commented error appears when the debugger is in the line private List<Equipo> equipos = new List<Equipo>();
I don′t know how to resolve it.
Thanks.
Hi,
Ensure that your code is debuggable. Make sure build configuration is set to Debug. Go to project properties | Compile Tab and make sure you are generating full debug information with optimizations disabled.
Also see the FAQ for this forum and provide all the info pointed out there so that folks can be of more help.
Azeem Khan
Visual Studio Debugger.