class Program
{
static void Main()
{
Console.WriteLine("Main Thread State={0}", Thread.CurrentThread.ThreadState.ToString());
Thread t = new Thread(ShowMessage);
Console.WriteLine("子 Thread State={0}", t.ThreadState.ToString());
t.Start();
Console.WriteLine("子 Thread State={0}", t.ThreadState.ToString());
//干掉子线程[等执行Abort期间,人家都执行完了...白等了,散伙吧...]
Thread.Sleep(2000);
t.Abort();
Console.WriteLine("子 Thread State={0}", t.ThreadState.ToString());
for (var i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
Console.ReadKey();
}
static void ShowMessage()
{
for (var i = 0; i < 10; i++)
{
Thread.Sleep(10);
Console.WriteLine(i);
}
}
}
{
static void Main()
{
Console.WriteLine("Main Thread State={0}", Thread.CurrentThread.ThreadState.ToString());
Thread t = new Thread(ShowMessage);
Console.WriteLine("子 Thread State={0}", t.ThreadState.ToString());
t.Start();
Console.WriteLine("子 Thread State={0}", t.ThreadState.ToString());
//干掉子线程[等执行Abort期间,人家都执行完了...白等了,散伙吧...]
Thread.Sleep(2000);
t.Abort();
Console.WriteLine("子 Thread State={0}", t.ThreadState.ToString());
for (var i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
Console.ReadKey();
}
static void ShowMessage()
{
for (var i = 0; i < 10; i++)
{
Thread.Sleep(10);
Console.WriteLine(i);
}
}
}