【发布时间】:2011-07-05 03:34:18
【问题描述】:
我有这个代码:
//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返回一个字符串。
如何捕获返回的字符串并返回?
【问题讨论】:
-
在类级别变量(字段)上分配字符串?
-
您将需要一个 IAsyncResult 在线程之间共享数据。但就其本质而言,异步函数无法返回数据。我可以为您编写一个示例,以便在线程之间安全地共享数据。这个控制台是什么应用程序类型?赢表格? WPF?网络?
标签: c# .net multithreading return-value