线程已被中止- “Thread was being aborted”
2013-05-07 14:13
513 查看
线程已被中止- “Thread was being aborted”
[code] using System;
using System.Threading;
using System.Security.Permissions;
public class ThreadWork {
public static void DoWork() {
try {
for(int i=0; i<100; i++) {
Console.WriteLine("Thread - working.");
Thread.Sleep(100);
}
}
catch(ThreadAbortException e) {
Console.WriteLine("Thread - caught ThreadAbortException - resetting.");
Console.WriteLine("Exception message: {0}", e.Message);
Thread.ResetAbort();
}
Console.WriteLine("Thread - still alive and working.");
Thread.Sleep(1000);
Console.WriteLine("Thread - finished working.");
}
}
class ThreadAbortTest {
public static void Main() {
ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork);
Thread myThread = new Thread(myThreadDelegate);
myThread.Start();
Thread.Sleep(100);
Console.WriteLine("Main - aborting my thread.");
myThread.Abort();
myThread.Join();
Console.WriteLine("Main ending.");
}
}
[/code]
[/code]
下面是输出结果:
Thread - working.
Main - aborting my thread.
Thread - caught ThreadAbortException - resetting.
Exception message: Thread was being aborted.
Thread - still alive and working.
Thread - finished working.
Main ending.
相关文章推荐
- 线程已被中止- “Thread was being aborted”
- Thread was being aborted Errors
- Thread was being aborted.(调试或执行较长时间的程序时发生的错误)
- 【求助】关于asp.net中的'Thread was being aborted'异常
- asp.net Thread was being aborted. 错误
- Thread was being aborted 分析与解决
- Thread was being aborted 分析与解决
- Thread was being aborted.你遇到了吗?
- ASP.NET程序中 抛出"Thread was being aborted. "异常(转)
- 由Response.Redirect引发的"Thread was being aborted. "异常
- SharePoint log分析——"Thread was being aborted"的可能情况
- ASP.NET程序中 抛出"Thread was being aborted. "异常
- 由Response.Redirect引发的"Thread was being aborted. "异常的处理方法
- System.Threading.ThreadAbortException: 正在中止线程。
- C# 关闭进程的时候总是捕捉到System.Threading.ThreadAbortException: 正在中止线程
- Android开发:如何安全的中止一个自定义线程Thread
- 关于解决 请求被中止:无法建立SSL / TLS安全通道(The request was aborted: Could not create SSL/TLS secure channel)的问题
- System.Threading.ThreadAbortException: 正在中止线程。
- System.Threading.ThreadAbortException: 正在中止线程
- Android开发笔记之:如何安全中止一个自定义线程Thread的方法