这是我正在使用的代码:
try
{
mainWorker = new BackgroundWorker();
mainWorker.DoWork += (sender, e) =>
{
try
{
//stuff I want to have happen in the background
...
//I want to step through the lines in this try block
}
catch
{
//exception not being caught
}
};
mainWorker.RunWorkerCompleted += (sender, e) =>
{
//code to let user know that the background work is done
...
};
mainWorker.RunWorkerAsync();
mainWorker.Dispose();
}
catch
{
//exception not being caught
}
我没有看到任何异常被抛出。我在DoWork的try块中设置了一个断点。有时它会触发断点,但是在执行一定数量的代码行之后程序就会结束。它并不总是在同一行代码结束,有时根本不会打断点。
如果我删除后台worker,代码会正常执行。
我以前没有实现过BackgroundWorker,现在我正在尝试弄清楚我错过了什么导致我不能逐步执行我的代码。
编辑: 忘了提到,即使我注释掉Dispose()也无法逐步执行。