private static object lock_o= new object();//互鎖量 private class lock_c //建立一個執行緒類 { private string ID; //要使用的引數 public COMMENTS_a(string id) { ID = id; } public void thr()//執行緒的函式 { lock (lock_o)//中間放要互鎖的程式碼 { Thread.Sleep(3000); } } } public static void COMMENTS(string ID) { lock_c trc = new lock_c (ID); Thread tr = new Thread(new ThreadStart(trc.thr)); tr.Start(); }