This is the Github Repository which I am using https://github.com/ilkerulutas/BinanceSdk
The code is working fine on a console application but it takes too much time to get a response in windows form application.
//Async Method
public async Task<TimeResponse> Time()
{
return await SendRequest<TimeResponse>("time", ApiVersion.Version1, ApiMethodType.None, HttpMethod.Get);
}
//Sync Method
public TimeResponse TimeSync() => Time().Result;
I am calling both but async method is giving status WaitingForActivation and Sync method is taking too much time to get response.
I am calling these 2 methods as
var timeResponseAsync = publicRestClient.Time(); //For Async
var timeResponseSync1 = publicRestClient.TimeSync(); // For Sync
You are deadlocking your UI thread.
My guess would be that you are calling
TimeSync()
which then calls aTask.Result
, which blocks the UI thread until theTask
returned fromTime()
is finished.As you have an
await
insideTime()
which starts on the UI thread, the async callback once the request is complete will be scheduled to happen on the UI thread, but this UI thread is already blocked by waiting for theTask.Result
. So therefore you are in a deadlocked situation.Could you show how you are using
TimeSync
and why are you using aSync
method which then uses anasync
method. To properly fix it, you need to make everything up the call chain async and await the result!One patch fix you can try is to do (this may or may not work, best case scenario it will still block the UI for the duration of the call):