Created
October 29, 2010 11:23
-
-
Save einaros/653358 to your computer and use it in GitHub Desktop.
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
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 |
But Visual Studio will draw squiggly lines below non-async calls to async methods, right?
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
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.