Is this code problematic?
- Yes. Because you are basically having an async void
method. Which is bad: See Avoid async void
Putting it into a Dictionary or any other datastructure will not improve on this.
Why don't I see people recommend against it more frequently?
In comments, we talked about Parallel.ForEach
and that there are a lot of recommendations or warnings to not mix it with async/await.
That's because there, the problem is the combination of the two. Parallel is perfectly fine. Async/await is perfectly fine. But if you mix them, they turn explosive.
async void
on the other hand is problematic in and by itself. So you'll probably read a lot of "dude, that method is async void, dont' do that", so that's what you'll be warned about. Not so much the combination with a Dictionary, which in itself is no problem. You could have a Dictionary<int, Func<TContext,Task>>
perfectly fine.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…