C# : quot;A first chance exception of type #39;System.InvalidOperationException#39;quot;(C#:“System.InvalidOperationException 类型的第一次机会异常)
问题描述
在 C# 中进行类分配时,我遇到了一个程序崩溃,没有任何错误(除了在 VS2010 的调试窗口中写入的内容).这是导致崩溃的典型代码:
Working on a class assignment in C#, I came across a program crash without any error (except what's written in VS2010's debug window). Here is the typical code causing the crash :
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);
}
}
}
...我在这里错过了什么?
... what am I missing here?
** 编辑 **
没有错误,程序只是结束,就像我调用 System.Environment.Exit(0);
There's no error, the program just ends like if I would call 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).
推荐答案
如果在异常窗口(Ctrl+Alt+E 在 Visual Studio 中),那么当您在调试时抛出异常时执行应该中断.
If you check Thrown for Common Language Runtime Exception in the break when an exception window (Ctrl+Alt+E in Visual Studio), then the execution should break while you are debugging when the exception is thrown.
这可能会让您对正在发生的事情有所了解.
This will probably give you some insight into what is going on.
这篇关于C#:“'System.InvalidOperationException' 类型的第一次机会异常"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C#:“'System.InvalidOperationException' 类型的第一次机会异常"
基础教程推荐
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
