[問題] 有關於 WaitOne 的使用

看板C_Sharp作者時間18年前 (2007/12/10 10:36), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
大家好 最近我想練習使用 WaitOne 所以寫了個程式 程式裡面會開另一個 thread 去 new 一個 form 出來, 然後原來的 thread 就 WaitOne 那個被新建出來的 form 上面有一個 buttom 按下那就會 Set() 可是.... 那個 form 每次建到一半整個程式就蕩掉了........ 這是我的主程式 using System; using System.Threading; namespace test2 { class MainClass { static private AutoResetEvent myWaker = new AutoResetEvent(false); static public Form1 myForm1; public static void Main(string[] args) { Console.WriteLine("Start to call"); ThreadPool.QueueUserWorkItem(new WaitCallback(newWaker) , myWaker); if (myWaker.WaitOne(-1, false)) { Console.WriteLine("get up"); } else { Console.WriteLine("oops"); } Console.WriteLine("finish"); } static void newWaker (object giveWaker) { myForm1 = new Form1(giveWaker); myForm1.Visible = true; } } } 請當作我寫的 form 是沒問題的....因為那是 #Develop 寫的........ 謝謝指教 <(_ _)> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.224.38.172 ※ 編輯: retrash 來自: 61.224.38.172 (12/10 10:36)

12/11 12:12, , 1F
WinForm程式要有message loop, 需要再加上 Application.Run
12/11 12:12, 1F

12/12 10:52, , 2F
謝謝 我待會試試 <(_ _)>
12/12 10:52, 2F
文章代碼(AID): #17NAOj_K (C_Sharp)