I'm writing a simplest caller console app according to this article with core3.1. When i changed channel.Open().Wait(5000);
to await channel.Open();
, it's stucked at line proxy.Ping();
.
And this is also found on a callee:
Task openTask = channel.Open();
openTask.Wait();
can't replace with await channel.Open();
Task<IAsyncDisposable> registrationTask = realm.Services.RegisterCallee(instance);
registrationTask.Wait();
can't replace with await realm.Services.RegisterCallee(instance);
Once await is used, the program always gets stuck at line proxy.Ping();
The solution zipfile.
Why?Isn't await waiting?
Your method call
proxy.Ping()
blocks the Websocket thread. If you use async syntax, you should be careful not to block the Websocket thread. Use theawait proxy.PingAsync()
version. If you need to make blocking calls likeConsole.ReadLine()
, make sure to release the Websocket thread by callingawait Task.Yield()
before making your blocking call.