Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

No More Deadlocks; Asynchronous Programming in .NET

2,937 views

Published on

In this talk I go over what asynchronous programming is, and how to use it. We will discover how to avoid potential deadlocks and what the best practices are in asynchronous programming in .NET.

Published in: Technology
  • Login to see the comments

No More Deadlocks; Asynchronous Programming in .NET

  1. 1. Author. Blogger. Speaker. .NET MVP. Xamarin MVP. Geek. Senior Software Engineer @
  2. 2. 12:38
  3. 3. var task = Task.Run(() => { Thread.Sleep(2000); return "Hello World!"; }); task.ContinueWith((completedTask) => { Dispatcher.Invoke(() => MyButton.Content = completedTask.Result); });
  4. 4. Task.Delay(1).ContinueWith((t) => { Dispatcher.Invoke(() => { }); }).Wait();
  5. 5. UsingAsyncandAwait
  6. 6. private async Task RunAsync() { var x = 10; await Task.Delay(2000); Debug.WriteLine(x); }
  7. 7. private Task RunAsync() { <RunAsync>d__1 stateMachine = new <RunAsync>d__1 { <>t__builder = AsyncTaskMethodBuilder.Create(), <>1__state = -1 }; stateMachine.<>t__builder.Start<<RunAsync>d__1>(ref stateMachine); return stateMachine.<>t__builder.Task; }
  8. 8. Deadlockallthethings!
  9. 9. Author. Blogger. Speaker. .NET MVP. Xamarin MVP. Geek. Senior Software Engineer @

×