Create a new thread in VB.NET

前端 未结 3 1744
粉色の甜心
粉色の甜心 2021-02-12 09:36

I am trying to create a new thread using an anonymous function but I keep getting errors. Here is my code:

New Thread(Function() 
    // Do something here
End Fu         


        
3条回答
  •  [愿得一人]
    2021-02-12 10:17

    What is called has to be a functinon not a sub.

    Single line(has to return value):

    Dim worker As New Thread(New ThreadStart(Function() 42))
    

    Multiline:

    Dim worker As New Thread(New ThreadStart(Function()
                                                         ' Do something here
                                                     End Function))
    

    Source: Threading, Closures, and Lambda Expressions in VB.Net

提交回复
热议问题