码迷,mamicode.com
首页 > 编程语言 > 详细

C#错误之 System.Threading.ThreadAbortException:正在中止线程

时间:2016-06-30 21:28:58      阅读:1947      评论:0      收藏:0      [点我收藏+]

标签:

参考:http://www.cnblogs.com/chendaoyin/archive/2013/06/27/3159211.html

1.开启一个子线程

1 //开启一个子线程,子线程调用方法 Method
2 Thread th = new Thread(Method);
3 th.IsBackground = true;
4 th.Start();

2.线程处理函数

 1 public void Method()
 2 {
 3     try
 4     { }
 5     catch(Exception ex)
 6     { 
 7         MessageBox.Show(ex.ToString(());
 8     }
 9     finally
10     {
11         th.abort();
12     }
13 }

此处的 Exception ex 用于捕获系统的异常,但是线程在执行过程中使用Abort方法关闭线程,会提示

 System.Threading.ThreadAbortException:正在中止线程的错误。

解决方法:

 1 public void Method()
 2 {
 3     try
 4     { }
 5     catch(ThreadAbortException ex)
 6     {
 7     //不进行操作
 8     }
 9     catch(Exception ex)
10     { 
11         MessageBox.Show(ex.ToString(());
12     }
13     finally
14     {
15         th.abort();
16     }
17 }

 

C#错误之 System.Threading.ThreadAbortException:正在中止线程

标签:

原文地址:http://www.cnblogs.com/imstrive/p/5631147.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!