using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace AsynchronousSample { class Sample1 { public delegate void PrintDelegate(string content); public static void Main() { Console.WriteLine("[The main process id:{0}]", Thread.CurrentThread.ManagedThreadId); Thread thread1 = new Thread(Print); thread1.Start(); Thread thread2 = new Thread(PrintEX); thread2.Start("test"); Console.ReadLine(); } public static void Print() { int threadID = Thread.CurrentThread.ManagedThreadId; Console.WriteLine("[The current process id:{0}]\t{1}", threadID, DateTime.Now.ToShortTimeString()); } public static void PrintEX(object content) { int threadID = Thread.CurrentThread.ManagedThreadId; Console.WriteLine("[The current process id:{0}]\t{1}", threadID, content); } } }
2012年8月23日 星期四
[C#]簡單Multiprocessing範例
直接上code,非常簡單明瞭.
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言