【发布时间】:2019-07-07 09:27:39
【问题描述】:
我想异步做一些事情,不关心结果。
最好的方法是什么?
Public Async Function HandlerForSomeEvent() As Task
'This is where I do stuff
'Then this is stuff I want to do without waiting for it
DoStuff()
'Here I continue doing other stuff
End Function
Async Sub DoStuff()
'Doing stuff while the handler continues doing it's stuff
End Sub
'VS
Async Function DoStuff() As Task
'Doing stuff while the handler continues doing it's stuff
End Function
每个人都告诉我使用Function As Task,但由于我不等待它,我总是在 VS 中收到烦人的警告。
有什么区别,我为什么要这样做?
【问题讨论】:
-
Async Sub仅用于事件处理程序。如果它实际上是一个事件处理程序,那么它应该是Async Sub,但一个事件处理程序也应该有适当的参数。如果不是事件处理程序,则不应为Async Sub。 -
@GSerg 那是 C#
-
@Fox 没关系。
-
@GSerg 你确定吗?
标签: vb.net asynchronous async-await task