How to implement Async Command

前端 未结 4 1791
轻奢々
轻奢々 2021-02-19 16:02

Although I have understood async programming with c# somehow, still don\'t get why async with void is not the better solution, then when I want to improve my Xamarin Forms code

4条回答
  •  萌比男神i
    2021-02-19 16:56

    You should always avoid async void occurrences in your code (exceptions of event handlers).

    Please refer this blog from Stephen for more detail

    Async void methods have different error-handling semantics. When an exception is thrown out of an async Task or async Task method, that exception is captured and placed on the Task object. With async void methods, there is no Task object, so any exceptions thrown out of an async void method will be raised directly on the SynchronizationContext that was active when the async void method started.

提交回复
热议问题