Live data from Hacker News

Beware of “async void” in C#

theburningmonk.com

21–24 of 24 posts

Re: Beware of “async void” in C#

#21
post #9

Earlier quoted context omitted.

"Would be nice if calling an async void method directly threw a compiler warning to make this completely clear." With VS 2015 and Roslyn, you can easily achieve this. In fact, there's already sample code to do this in the roslyn samples project[0]. [0] https://github.com/dotnet/roslyn/tree/master/src/Samples/CSh...

The ability to write my own analyzers shouldn't be a substitute for a well-curated set of code analysis checks out of the box, though. I want to spend my time building my product, not building the tooling so I can build my product. (Note that I haven't had the opportunity to play with VS2015 yet; for all I know, these checks from the Roslyn samples might already be provided with the IDE.)

Analyzers are available as NuGet packages, so it should be a trivial process to install one of these in your project.

We're definitely going to start shipping some high-value analyzers in the box (probably including the async-void one).

Re: Beware of “async void” in C#

#23
post #10

Earlier quoted context omitted.

I've been pleasantly surprised by the async workflows in F#. Behind the scenes it is one big ass monadic construct that has been grafted onto the language, but it doesn't feel that way at all when you use it...it is incredibly elegant and easy to read/write and understand exactly what is happening in terms of control flow. I think it is perfectly possible for C# to improve it without starting over from scratch, simpl…

Yeah, but the problem with C# is not that it isn't working, and it is pretty legible and easy to understand. The problem is the syntax and lack of some abstractions. F# syntax is probably more suited for a certain style of programming. You could try to rework C# without concern for breaking current behavior and making it more cohesive and consistent... but at that point it won't be C# I think. What I'd really like th…

You pretty much just described data parallel Haskell to a T:

https://wiki.haskell.org/GHC/Data_Parallel_Haskell

Re: Beware of “async void” in C#

#24

This is a rough one, because while Microsoft's own docs tell you not to use async void, all of their demo code that I've seen does. Granted, it's demo code and not production code, but less experienced developers do not always pick up on that.

There are often some startlingly bad practices in some of the Microsoft sample code. I've worked with an SDK where the majority of the example projects would crash out before illustrating the point of the example, because event callbacks that were hit by the code executed in the sample were just stubbed in with

    throw new NotImplementedException();
Post reply on HN