Skip to content

Instantly share code, notes, and snippets.

@shaxxx
Created November 21, 2014 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaxxx/855e21dc27792c45ebcb to your computer and use it in GitHub Desktop.
Save shaxxx/855e21dc27792c45ebcb to your computer and use it in GitHub Desktop.
Use async await pattern inside any method
button.Click += async (x,y) => {
int parameter = 1;
System.Threading.Tasks.Task<bool> task;
task = Task.Run(() =>
{
System.Threading.Thread.Sleep(3000);
return parameter == 1;
});
button.Text = "Waiting...";
await task;
if (task.Result)
{
button.Text = "TRUE";
}
else
{
button.Text = "FALSE";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment