Steve Dunn
Steve Dunn

Reputation: 21741

Does using TaskCompleteSource.Wait block the thread that creates it?

I've got a Task. It creates a TaskCompletionSource and Waits for some other thing to set its Result.

In the call to myTaskCompletionSource.Wait():

  1. Is the thread that created it blocked?
  2. Can TPL reuse the thread to service other tasks?

Upvotes: 0

Views: 64

Answers (1)

Scott Chamberlain
Scott Chamberlain

Reputation: 127543

  1. The thread that called myTaskCompletionSource.Wait() gets blocked, the creator of myTaskCompletionSource is not affected by the call.
  2. No, the thread is totally blocked. if you wanted the thread to be available for other tasks you would need to await on it via await myTaskCompletionSource;.

Upvotes: 2

Related Questions