首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C#:“‘System.InvalidOperationException’类型的第一次机会异常”

C#:“‘System.InvalidOperationException’类型的第一次机会异常”
EN

Stack Overflow用户
提问于 2010-12-09 06:38:28
回答 2查看 123.9K关注 0票数 58

在C#的一个类赋值工作中,我遇到了一个程序崩溃,没有任何错误(除了在VS2010中的调试窗口中写的东西)。下面是导致崩溃的典型代码:

代码语言:javascript
复制
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);一样结束了

代码语言:javascript
复制
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).
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4393092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档