M
M
Michael2016-11-01 14:50:52
.NET
Michael, 2016-11-01 14:50:52

How does TaskCompletionSource work in C#?

Tell me exactly how TaskCompletionSource works in C#.
Interested in the following questions:
1. When using TaskCompletionSource, a new thread (Task) is created?
2. If not created, then in which thread does it wait for SetResult to be set?
3. Is there any difference from ManualResetEvent (besides returning Task), which blocks the thread until it waits?
4. Would it be beneficial to replace the ManualResetEvent with a TaskCompletionSource if the event is waiting for a message from outside the socket?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2016-11-01
@Sing303

Description of work: andrey.moveax.ru/post/csharp-sync-to-async
And from it:
1. You create a new thread if necessary. The TaskCompletionSource only creates an instance of type Task
2. It waits in the volume that requested the result.
3. ManualResetEvent works with the "event" kernel object, and this object does not block the thread.
4. "event" you can always check for the state and if it is not a signal, but continue the necessary things.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question