我有這樣的代碼:
//Asynchronously start the Thread to process the Execute command request.
Thread objThread = new Thread(new ParameterizedThreadStart(ExecuteCommandSync));
//Make the thread as background thread.
objThread.IsBackground = true;
//Set the Priority of the thread.
objThread.Priority = ThreadPriority.AboveNormal;
//Start the thread.
objThread.Start(command);
的問題是,ExecuteCommandSync
返回一個字符串。
如何捕獲返回的字符串並將其返回?
在類級變量(字段)上分配字符串? – Predator
http://stackoverflow.com/questions/1314155/returning-a-value-from-thread – adt
你將需要一個IAsyncResult來在線程之間共享數據。但就其性質而言,異步函數不能返回數據。我可以給你寫一個樣本,以便在線程之間安全地共享數據。此控制檯有哪些應用程序類型? WinForm的? WPF?網? –