the second command seems to do nothing. What is the reason?
The second method is asynchronous, which means exceptions are never thrown directly to the caller - whether the exception occurs while the method is executing synchronously or not. An async method which returns a Task
will make the task "faulted" if the method throws an exception... but when the async method is void
(which should almost never be the case) it call AsyncVoidMethodBuilder.SetException
- the behaviour of which will depend on the synchronization context.
The async
modifier is definitely not redundant in that it does affect behaviour, as you've noted - and that's the correct behaviour, working as designed... it's just that when an async void
method throws an exception, there's the natural question of what should catch it.