是否可以防止 Visual Studio 在 BackgroudWorker.DoWork 内出现异常时中断
问题是应用程序应该处理 以某种方式工作。在我的应用程序的发布版本中,我生成一个错误是为了测试它,并且没有执行它应该执行的操作,但是如果我调试,那么 VS 将在异常处中断,而不是将其传递给 RunWorkerCompleted 这是根据 DoWork 文档。有没有什么方法可以防止 VS 在异常处停止并使其执行发布后在调试时执行的操作,以便我可以看到我的代码出了什么问题?
@ChrisF:这是我的代码。我认为这不会有多大帮助:
void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if(null == e.Error) OnDownloadComplete(new DownloadCompleteEventArgs(e.Cancelled, null, e.Result as string));
else OnDownloadComplete(new DownloadCompleteEventArgs(false, e.Error, null));
}
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
throw new Exception("OMG!!!");
}
如果不可能做我想做的事情,我可以尝试寻找另一种方法来查找我的错误。我认为发布更多代码不是一个好主意,因为它会与 OnDownloadComplete
纠缠在一起,并且错误可能出现在任何地方。只需要先放弃调试的可能性即可。
The problem is that the application is supposed to handle errors that occur inside DoWork in a certain way. In a published version of my app, I'm generating an error in purpose to test it and is not doing what it is supposed to do, but if I debug then VS will break at the exception instead of passing it to RunWorkerCompleted
which is what would happen after published (or when not running under the VS debugger) according to the DoWork documentation. Is there any way to prevent VS from stopping at the exception and make it do what it would do after published while debugging so I can see what's wrong with my code?
@ChrisF: Here's my code. I don't think it will help much:
void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if(null == e.Error) OnDownloadComplete(new DownloadCompleteEventArgs(e.Cancelled, null, e.Result as string));
else OnDownloadComplete(new DownloadCompleteEventArgs(false, e.Error, null));
}
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
throw new Exception("OMG!!!");
}
If is not possible to do what I'm trying to do I can try to find another way to find my error. I don't think is a good idea to post more code since it gets pretty entangled in OnDownloadComplete
and the error can be anywhere. Just need to discard the possibility to debug first.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DebuggerHidden
可以在这里使用异常冒泡到 RunWorkerCompleted 事件。
DebuggerHidden
can be used here to let the exception bubble up to the RunWorkerCompleted event.
这肯定是重复的,但无论如何...您应该在 Visual Studio 中打开“调试/异常...”对话框,查找您希望 VS 忽略的异常,并禁用“抛出”复选框。
This is sure to be a duplicate, but anyway... you should open the dialog Debug/Exceptions... in visual studio, lookup the exception you want VS to ignore, and disable the 'thrown' checkbox.