I can perform an async action using Task.Run
like so
await Task.Run(() =>
{
DoSomeIOStuff();
//throw new Exception("Custom Exception");
});
Sometimes I need a value returned
bool success = await Task.Run(() => ...
But sometimes I don't. I'd read that you should never have an async method with a return of void because, among other things, you can get lost exceptions (as outlined in this question). I tested the above Task.Run call with an exception in it and found that all of the data was handled, which meant that Task.Run was still returning a task even if I wasn't returning anything. Then I tried
var temp = await Task.Run(() =>
Which gives me an error that I can't assign void to a variable, which I would expect, but that leaves me wondering what Task.Run is returning. It's acting like it's returning a Task of nothing, so while I assume that's not what's happening, I haven't found any documentation about what it's doing. Any thoughts?