关于C#线程终止的问题 强行终止你就加 try{} catch{} 只能这样 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Thread的Abort方法会触发一个异常(具体什么没看过)我每次都调用Abort方法 终止线程如果你不想看到异常 而又必须强行终止的话 试试这个类public class MyThread :IDisposable { Thread ths = null; public bool IsWork { get; set; } public MyThread() { IsWork = true; ths = new Thread((obj) => { while (IsWork) { Console.WriteLine(Guid.NewGuid().ToString()); Thread.Sleep(1000); } }); ths.IsBackground = true; ths.Start(); } public void Dispose() { } } class Program { static void Main(string[] args) { MyThread ths = new MyThread(); Thread.Sleep(10000); ths.IsWork = false; Console.ReadLine(); } }额 你问的是这个吗 请教怎么获取框架中的网页上的数据? 请求一个sql语句!!!!! 数据库的连接 在webmenu中怎么新开一个窗口,显示连接的页面????(白分相送) FastReport报表设计问题 关于这本书 dataTable GetChanges() 如何直接将DataSet中的数据直接导出为Excel文件? 是BUG吗? 提问!!!WEBBROWSER控件的详细用法,请告知,如何才不会打开新窗口呢 datatable.select()排序问题 System.IO.FileNotFoundException问题求解
我每次都调用Abort方法 终止线程
如果你不想看到异常 而又必须强行终止的话 试试这个类
public class MyThread :IDisposable
{
Thread ths = null; public bool IsWork { get; set; } public MyThread()
{
IsWork = true;
ths = new Thread((obj) =>
{
while (IsWork)
{
Console.WriteLine(Guid.NewGuid().ToString());
Thread.Sleep(1000);
}
});
ths.IsBackground = true;
ths.Start();
} public void Dispose()
{
}
}
class Program
{
static void Main(string[] args)
{
MyThread ths = new MyThread();
Thread.Sleep(10000);
ths.IsWork = false;
Console.ReadLine();
}
}
额 你问的是这个吗