Mar*_*ood 1 .net multithreading compact-framework exception-handling
我正在尝试处理.NET CF程序如下所示的其他线程上发生的错误:
static void Main()
{
Thread t = new Thread(Start);
t.Start();
...
}
void Start()
{
... Exception here
}
Run Code Online (Sandbox Code Playgroud)
在我的情况下,在Start方法中放置try catch是不可能的.我如何在全局代码中处理它?
如果没有进入异常处理的最佳实践,您可以使用填充方法来执行您想要的操作,例如
static void Main()
{
Thread t = new Thread(Shim);
t.Start();
...
}
void Shim()
{
try
{
Start();
}
catch
{
//If there's something you can really do about it...
}
}
void Start()
{
... Exception here
}
Run Code Online (Sandbox Code Playgroud)
更新
如果您指的是NUnit忽略非测试线程上的异常的方式,请参阅我写的一篇博客文章,其中描述了与ReSharper测试运行器相同的问题\功能.它由legacyUnhandledExceptionPolicy控制.
http://gojisoft.com/blog/2010/05/14/resharper-test-runner-hidden-thread-exceptions/
| 归档时间: |
|
| 查看次数: |
612 次 |
| 最近记录: |