Skip to content

Instantly share code, notes, and snippets.

@einaros
Created October 29, 2010 11:23
Show Gist options
  • Save einaros/653358 to your computer and use it in GitHub Desktop.
Save einaros/653358 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
Console.Out.WriteLine("Baking cookies");
BakeCookies();
Console.Out.WriteLine("Cookies baked");
Console.ReadLine();
}
private static async void BakeCookies()
{
await TaskEx.Run(() =>
{
Thread.Sleep(1000);
Console.Out.WriteLine("Done baking");
});
}
}
Output:
Baking cookies
Cookies baked
Done baking
@einaros
Copy link
Author

einaros commented Oct 29, 2010

In days gone by -- and especially before the task parallel library's arrival -- writing proper asynchronous methods was so painful, there was simply no way you'd not brag about it in the method name.

Now that everyone and their grandmother will be able to do it, I wouldn't be surprised to see methods similar to 'BakeCookies' above, not properly named as (e.g.) BakeCookiesAsync; or with no clear indicator for when the asynchronous method completes.

@tormodfj
Copy link

But Visual Studio will draw squiggly lines below non-async calls to async methods, right?

@einaros
Copy link
Author

einaros commented Oct 29, 2010

That's entirely possible, but I haven't seen any comments on it in the specs or whitepapers.

That said, I'd much rather have clear naming, than yet more warning and information markers within VS :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment