using System;
using System.Threading;
namespace C17_6
{
public class MyThread
{
public void TestThread()
{
for (int i = 0; i < 2; i++)
{
Thread t = Thread.CurrentThread;
Console.WriteLine(t.Name+"="+i);
Thread.Sleep(1);
}
}
}
public class Test
{
public static void Main()
{
Console.WriteLine("開始啟動執行緒:");
MyThread myThread = new MyThread();
Thread t1 = new Thread(new ThreadStart(myThread.TestThread));
Thread t2 = new Thread(new ThreadStart(myThread.TestThread));
t1.Name = "執行緒A";
t2.Name = "執行緒B";
t1.Priority = ThreadPriority.Highest;
t2.Priority = ThreadPriority.Lowest;
try
{
t1.Start();
t2.Start();
}
catch (ThreadStartException e)
{
Console.WriteLine(e.Message);
}
t1.Join();
t2.Join();
Console.WriteLine("程式運行完畢");
}
}
}
沒有留言:
張貼留言