Wednesday, October 16, 2019

Coding Standards, Guidelines and Best Practices: Avoid Aysnc Void


Getting Started with Asynchronous Programming in .NET


Use Async Void


Async Void is only appropriate for Event Handler
protected async void search_click( object sender, RouteEventArgs e)
{
     await GetStocks()


Alternate Solution 

private async Task GetStock()
{

}

Take Away:
Async Void crashes an application or may results in 500 exception if something went wrong. As there is no way to propagate exception even you have proper try catch. 

Call GetStock()

private async void GetStock()
{
 try
{}
catch()
}

No comments :