【发布时间】:2011-08-16 10:40:01
【问题描述】:
这是我编写的代码,它通常可以工作,但有时会失败(4 次中的 1 次或多或少):
...
List<string> _items = new List<string>();
...
using (SqlCeConnection con = new SqlCeConnection(Globals.conString))
{
string codbultocomp = null;
con.Open();
using (SqlCeCommand cmd = new SqlCeCommand("SELECT codbultocomp FROM envios WHERE codigodestino=@codigodestino AND estado=@pendiente", con))
{
cmd.Parameters.AddWithValue("@codigodestino", codigoDestino);
cmd.Parameters.AddWithValue("@pendiente", "pendiente");
SqlCeDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
codbultocomp = reader["codbultocomp"].ToString();
_items.Add(codbultocomp);
}
reader.Close();
}
listBox1.DataSource = _items;
}
当它失败时,应用程序会冻结,如果我暂停调试,它会在最后一个大括号中停止。我尝试使用 try/catch 块显示错误,但它没有显示任何内容并停在同一个地方。我还尝试观察列表框数据源在“观察”列表中显示此错误:
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
知道我做错了什么吗?
【问题讨论】:
-
这是在后台线程上运行的吗?
-
这是一个 Windows CE 应用程序。该应用程序以具有不同选项的菜单开始,此代码来自选项之一。当在菜单中选择一个选项时,会出现一个代表该选项的新表单,并且菜单表单留在后面。
标签: c# list listbox datasource