Should I avoid 'async void' event handlers?

后端 未结 4 2111
-上瘾入骨i
-上瘾入骨i 2020-11-22 16:19

I know it is considered generally a bad idea to use fire-and-forget async void methods to start tasks, because there is no track of the pending task and it is t

4条回答
  •  时光说笑
    2020-11-22 16:55

    Should I generally avoid async void event handlers, as well?

    Generally event handlers are the one case where a void async method is not a potential code smell.

    Now, if you do need to track the task for some reason then the technique you describe is perfectly reasonable.

提交回复
热议问题