日期:2014-05-16 浏览次数:20834 次
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();
}
}