I have read around about why you should avoid async void methods, and async void lambdas. However, I'm still not clear how I avoid them when I'm not the author of the method that takes the lambda.
For example, this blog post and this one both explain the problem clearly. However, the solution they offer is to modify the method (the Time method in that second link) to accept a Func rather than an Action.
That's all fine when you are the one writing the methods. What do you do if this isn't the case? For example, consider this rather pointless piece of code...
new List<int>()
.ForEach(async n => {
await Task.Delay(1);
});
Resharper warns that you should avoid using an async lambda when the delegate type returns void. How would I avoid that?
Another example would be...
var modifiedCollection = someCollection
.Select(async x => await DoSomething(x));
I'm not the author of Linq, so cannot change Select to accept a Func, so how do I avoid the problem?
Thanks for any clarification you can give.
