// Called from Thread Id 1
await SomeMethodAsync();
// Continues on Thread Id 5
// await Task.Yield() - fixes the issue
Console.ReadKey(); // example to block the thread
class Sample
{
Task SomeMethodAsync()
{
var tcs = new TaskCompletionSource();
queue.Enqueue(tcs);
return tcs.Task;
}
void OnMessage()
{
// Called from Thread Id 5
var tcs = queue.Dequeue();
tcs.TrySetResult(); // Blocks the whole event loop
// Do some other stuff
}
}
// Called from Thread Id 1
await SomeMethodAsync();
// Continues on Thread Id 5
// await Task.Yield() - fixes the issue
Console.ReadKey(); // example to block the thread
class Sample
{
Task SomeMethodAsync()
{
var tcs = new TaskCompletionSource();
queue.Enqueue(tcs);
return tcs.Task;
}
void OnMessage()
{
// Called from Thread Id 5
var tcs = queue.Dequeue();
tcs.TrySetResult(); // Blocks the whole event loop
// Do some other stuff
}
}