Question

.Net framework 4.5 await authorize hangs

  • 5 June 2019
  • 3 replies
  • 5167 views

I am running below code from my console application and it works perfectly and I can fetch data

static async Task GetCallLogs() {
 var rc = new RestClient(RINGCENTRAL_CLIENT_ID, RINGCENTRAL_CLIENT_SECRET, RINGCENTRAL_PRODUCTION_URL); await rc.Authorize("username", "ext", "password"); 
// making api calls
}


But when I am doing the same thing from the .NET framework controller, system hangs at await

public void  UpdateRingCentral()
   {
             var t= new GetCallLogs();
             t.Wait();
   }
public async Task GetCallLogs() { 
var rc = new RestClient(RINGCENTRAL_CLIENT_ID, RINGCENTRAL_CLIENT_SECRET, RINGCENTRAL_PRODUCTION_URL); await rc.Authorize("username", "ext", "password"); 
// making api calls
}


Any advice or suggestions for fixing this issue.


3 replies

This article helped in fixing this issue.

https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html

This is a very common feature of .net platform which arise deadlock condition during making the actual REST call and parsing it as JSON .

There are many ways you can prevent this mentioned here .

Also refer here to get your answer

Another link you should read:

https://devblogs.microsoft.com/pfxteam/await-and-ui-and-deadlocks-oh-my/

There is fee more docs available on these type of issue here.

Reply