public BadMainViewModelA() { // BAD CODE!!! UrlByteCount = MyStaticService.CountBytesInUrlAsync("http://www.example.com").Result; // APP wont show up until this code finishes. // Possibility of deadlock. }
public MainViewModel() { UrlByteCount = new NotifyTaskCompletion <int>( MyStaticService.CountBytesInUrlAsync("http://www.example.com")); }
// BAD CODE!!! // any errors raised by the asynchronous operation will crash the application by default private async void Initialize() { UrlByteCount = await MyStaticService.CountBytesInUrlAsync( "http://www.example.com"); }