Where can I find the ThreadPool.SwitchTo method?

I am learning the new Async CTP and looking through some sample code,

I came across this piece of code:

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; 
}

Please, where can I find ThreadPool.SwitchTo? The SwithcTo method does not belong to the ThreadPool class.

I have a link to AsyncCtpLibrary.dll ... but not luck

+3
source share
2 answers

For reference, CharlesO answered his question in the comments above:

OK, guys found this. Summary: Provides methods for interacting with ThreadPool. Remarks: ThreadPoolEx is a placeholder.

Sharing Function SwitchTo () As System.Runtime.CompilerServices.YieldAwaitable Member System.Threading.ThreadPoolEx Summary: Creates asynchronously gives ThreadPool when waiting.

+2

ThreadPool.SwitchTo , anit-. , , , . finally , await finally.

public async void button1_Click(object sender, EventArgs e) 
{ 
  await ThreadPool.SwitchTo();
  try
  {
    // Do something dangerous here.
  }
  finally
  {
    await button1.Dispatcher.SwitchTo(); // COMPILE ERROR!
  }

}

, , . , Task.Run 1 await.

+1

Source: https://habr.com/ru/post/1788153/


All Articles