zoukankan      html  css  js  c++  java
  • C#错误之 System.Threading.ThreadAbortException:正在中止线程

    参考: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 }
  • 相关阅读:
    linux virtualbox
    cboard安装
    test
    kafka安装
    OLAP解释
    php 连接数据库直接转成json格式
    hive学习
    mariadb修改密码
    mariadb anzhuang
    IDEA12 中写hql语句编译器莫名报错
  • 原文地址:https://www.cnblogs.com/imstrive/p/5631147.html
Copyright © 2011-2022 走看看