【发布时间】:2011-06-16 11:03:59
【问题描述】:
我正在研究新的 Async CTP 并查看一些示例代码,
我遇到了这段代码:
public async void button1_Click(object sender, EventArgs e)
{
string text = txtInput.Text;
await ThreadPool.SwitchTo(); // jump to the ThreadPool
string result = ComputeOutput(text);
string finalResult = ProcessOutput(result);
await txtOutput.Dispatcher.SwitchTo(); // jump to the TextBox’s thread
txtOutput.Text = finalResult;
}
请问我在哪里可以找到 ThreadPool.SwitchTo? SwithcTo 方法不在 ThreadPool 类上
我有一个 AsyncCtpLibrary.dll 的参考...但没有运气
【问题讨论】:
-
对我来说它看起来像是一种扩展方法。
-
假设您已经在 Visual Studio 中加载了代码,右键单击方法名称并选择“转到定义”。它将立即将您带到定义该方法的位置,以便您可以研究它。我怀疑 chibacity 的假设是在
ThreadPool类之外的其他地方定义的扩展方法是正确的。 -
我虽然如此,但从哪里来?我添加了对 AsyncCtpLibrary.dll 的引用,但没有运气
-
您必须添加正确的
using才能使用扩展方法。 -
@CharlesO:如果您想通了,请将其发布为将来帮助他人的答案。
标签: .net asynchronous threadpool async-ctp