using System;
using System.Threading;
namespace C17_3
{
public class MyThread
{
string n;
public MyThread(string n)
{
this.n = n;
}
public void TestThread()
{
for (int i = 0; i < 3; i++)
{
Console.WriteLine("執行緒{0}:{1}", n,i);
}
}
}
public class Test
{
public static void Main()
{
Console.WriteLine("開始啟動執行緒:");
MyThread myThread1 = new MyThread("a");
MyThread myThread2 = new MyThread("b");
ThreadStart ts1 = new ThreadStart(myThread1.TestThread);
ThreadStart ts2 = new ThreadStart(myThread2.TestThread);
Thread a = new Thread(ts1);
Thread b = new Thread(ts2);
a.Start();
b.Start();
}
}
}
沒有留言:
張貼留言