Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question