Skip to content

Instantly share code, notes, and snippets.

@fekberg
Created March 11, 2013 20:27
Show Gist options
  • Save fekberg/5137441 to your computer and use it in GitHub Desktop.
Save fekberg/5137441 to your computer and use it in GitHub Desktop.
Deadlock example with async/await
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace DeadlockExample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var run = new Button();
run.Content = "Run!";
run.Click += Run_Click;
Content = run;
}
async Task Run()
{
var runningTask = Task.Delay(2000);
await runningTask;
MessageBox.Show("Hey!");
}
void Run_Click(object sender, RoutedEventArgs e)
{
Run().Wait();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment