如您所知,我们在 vb.net 中有一个新语法,可以创建内联任务,以便我们可以异步运行它。
这是正确的代码:
Dim testDeclaring As New Task(Sub()
End Sub)
testDeclaring.Start()
但现在我需要在子例程中传递一个参数,但我找不到正确的语法。
有可能吗?
最佳答案
这是不可能的。但是,您可以只使用当前范围内的参数:
Public Function SomeFunction()
Dim somevariable as Integer = 5
Dim testDeclaring As New Task(Sub()
Dim sum as integer = somevariable + 1 ' No problems here, sum will be 6
End Sub)
testDeclaring.Start()
End Function
关于vb.net - 如何使用参数将新任务声明为 SUB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16119864/