我有以下代碼:線程與參數失敗
Thread userThread = new Thread(() => UserPasswordSpawn.InputBox(ref userName, ref password));
//UserPassWordSpawn.InputBox(ref userName, ref password);
/* do some calculations while user puts in data */
userThread.Join();
線程不工作,從來沒有進入的InputBox()函數(我設置一個斷點,而這是從來沒有達到),而它的工作原理如果我執行註釋部分(但是在系統等待用戶輸入數據時應該發生的計算),那就好了。我怎樣才能用2個輸入參數正確地產生一個線程(兩次參考字符串)。
請注意,我得到的錯誤是關於Thread.JoinInternal(),但主要的事情可能是該函數未被調用。
與()=>的ThreadStart()的調用,我從How to pass parameters to ThreadStart method in Thread?
'userThread.Start();':) –
你沒有啓動線程。爲什麼不使用像這樣創建的tpl.threads代價高昂 –
我沒有看到userThread.start()。你是否也可以包含你的代碼的一部分? – ryadavilli