下面这段代码,
public static void test()
{
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(ExceptionMethod));
try
{
thread.Start();
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
} public static void ExceptionMethod()
{
throw new Exception("Error.");
}会出错,原因是try捕捉不到thread 里的例外,有什么办法可以让try捕捉得到呢?除了在ExceptionMethod方法里面加try外。
public static void test()
{
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(ExceptionMethod));
try
{
thread.Start();
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
} public static void ExceptionMethod()
{
throw new Exception("Error.");
}会出错,原因是try捕捉不到thread 里的例外,有什么办法可以让try捕捉得到呢?除了在ExceptionMethod方法里面加try外。
解决方案 »
- 关于数组的问题, 请赐予我答案!
- webbrowser获取窗体内的图片
- c# 画了若干的圈,导致速度过慢如何处理?
- 如何在后台获取HTML控件(不加runat="server")的值
- C#调用C++dll 指针传递错误
- 我已经写好了一个windows的服务,但不知怎么安装,我要做成安装包,请给出详细的步骤
- 哪位朋友肯提供一下用WEBFORM对 sql server2000数据库增删改,更新的程序???谢谢!!!!!!!
- 初学c#的困惑
- c#智能应用
- c# 如何将视频打包成一个exe可执行文件播放
- OracleDataAdapter.Update 批量新增时只新增了一部分数据
- C# 中如何引用Ture Type字体里面的某一个字符啊?
{
try
{
Func func = new Func(ExceptionMethod);
IAsyncResult res = func.BeginInvoke(null, null);
func.EndInvoke(res);
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
}
而且,一般不建议使用Thread.Abort,用其他想成同步方法会更可靠一些。