私はこのコードを持っている:
//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?ウェブ? –