Created
March 11, 2013 20:27
-
-
Save fekberg/5137441 to your computer and use it in GitHub Desktop.
Deadlock example with async/await
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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