1. 程式人生 > >C#多執行緒程式設計實現方式

C#多執行緒程式設計實現方式

複製程式碼
namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread t1 = new Thread(new ThreadStart(TestMethod));
            Thread t2 = new Thread(new ParameterizedThreadStart(TestMethod));
            t1.IsBackground = true;
            t2.IsBackground = true
; t1.Start(); t2.Start("hello"); Console.ReadKey(); } public static void TestMethod() { Console.WriteLine("不帶引數的執行緒函式"); } public static void TestMethod(object data) { string datastr = data as
string; Console.WriteLine("帶引數的執行緒函式,引數為:{0}", datastr); } } }
複製程式碼