【发布时间】:2011-05-22 12:59:37
【问题描述】:
在 C# 中进行类分配时,我遇到了一个程序崩溃,没有任何错误(除了在 VS2010 的调试窗口中写入的内容)。这是导致崩溃的典型代码:
public partial class Test : Form
{
public Test()
{
InitializeComponent();
}
private void Test_Load(object sender, EventArgs e)
{
ColumnHeader header;
header = new ColumnHeader();
header.Text = "#";
header.TextAlign = HorizontalAlignment.Center;
header.Width = 30;
listView1.Columns.Add(header);
TimerCallback tcb = this.UpdateListView;
System.Threading.Timer updateTimer = new System.Threading.Timer(tcb, null, 0, 1000);
}
public void UpdateListView(object obj)
{
ListViewItem item;
listView1.Items.Clear();
for (int i = 0; i < 10; i++)
{
item = new ListViewItem(i.ToString());
listView1.Items.Add(item);
}
}
}
...我在这里错过了什么?
** 编辑 **
没有错误,程序只是结束,就像我打电话给System.Environment.Exit(0);
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
The program '[4644] ProgramTest.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
The program '[4644] ProgramTest.vshost.exe: Program Trace' has exited with code 0 (0x0).
【问题讨论】:
-
堆栈跟踪?抛出异常时的代码行?