VB.NET:启动新线程时声明预期错误

问题描述 投票:-2回答:1
Public Class Class1
    Dim thread As New System.Threading.Thread(AddressOf AMethod)
    thread.Start()

    Public Sub AMethod()
        Console.writeline("Thread start") 
    End Sub
End Class

根据vb,“thread.Start()”是有问题的一行。无论这意味着什么,在sub中声明线程都会产生重载错误。

vb.net multithreading
1个回答
0
投票

如果你不明白@Plutonix的意思是“可执行代码浮动”(我喜欢这句话),这里有一个例子:

Public Class Class1
    Dim thread As New System.Threading.Thread(AddressOf AMethod)

    Public Sub StartingThread()
        thread.Start()
    End Sub

    Public Sub AMethod()
        Console.WriteLine("Thread start")
    End Sub
End Class

请参阅可执行代码thread.Start()现在位于方法中。我,我自己,我正在避免线程,直到我了解更多。

© www.soinside.com 2019 - 2024. All rights reserved.