本文整理汇总了C#中System.Threading.Thread.ResetAbort方法的典型用法代码示例。如果您正苦于以下问题:C# Thread.ResetAbort方法的具体用法?C# Thread.ResetAbort怎么用?C# Thread.ResetAbort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Thread
的用法示例。
在下文中一共展示了Thread.ResetAbort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Thread.ResetAbort()
//引入命名空间
using System;
using System.Threading;
class MyThread {
public Thread thrd;
public MyThread(string name) {
thrd = new Thread(this.run);
thrd.Name = name;
thrd.Start();
}
void run() {
Console.WriteLine(thrd.Name + " starting.");
for(int i = 1; i <= 100; i++) {
try {
Console.Write(i + " ");
Thread.Sleep(50);
} catch(ThreadAbortException exc) {
if((int)exc.ExceptionState == 0) {
Console.WriteLine("Abort Cancelled! Code is " + exc.ExceptionState);
Thread.ResetAbort();
} else
Console.WriteLine("Thread aborting, code is " + exc.ExceptionState);
}
}
Console.WriteLine(thrd.Name + " exiting normally.");
}
}
class MainClass {
public static void Main() {
MyThread mt1 = new MyThread("My Thread");
Thread.Sleep(1000);
Console.WriteLine("Stopping thread.");
mt1.thrd.Abort(100);
mt1.thrd.Join();
Console.WriteLine("Main thread terminating.");
}
}