这个链接很好地回答了如何创建一个委托,然后将其回调到主线程。
vb.net threading.thread 传递变量的地址
另一个很好的通用示例:
thread = New System.Threading.Thread(AddressOf DoStuff)
thread.Start()
Private Delegate Sub DoStuffDelegate()
Private Sub DoStuff()
If Me.InvokeRequired Then
Me.Invoke(New DoStuffDelegate(AddressOf DoStuff))
Else
Me.Text = "Stuff"
End If
End Sub
http://tech.xster.net/tips/invoke-ui-changes-across-threads-on-vb-net/
由于您没有提供代码,因此我无法根据您的需要定制我的答案。相反,我从 MSDN 复制了一个通用解决方案。
线程可以以不同的方式使用,在 vb.net 中,GUI 在一个线程上运行,因此需要在单独的线程上处理许多进程以阻止 GUI 锁定。
实现这一点有许多排列方式,但是此代码和此页面提供的链接将为您提供至少入门所需的所有信息。
如果您的代码无法正常工作,请随时提出另一个更具体的问题来显示您的代码,我和/或其他人会很乐意为您提供帮助。
来自 MSDN 的示例。
Imports System
Imports System.Threading
' Simple threading scenario: Start a Shared method running
' on a second thread.
Public Class ThreadExample
' The ThreadProc method is called when the thread starts.
' It loops ten times, writing to the console and yielding
' the rest of its time slice each time, and then ends.
Public Shared Sub ThreadProc()
Dim i As Integer
For i = 0 To 9
Console.WriteLine("ThreadProc: {0}", i)
' Yield the rest of the time slice.
Thread.Sleep(0)
Next
End Sub
Public Shared Sub Main()
Console.WriteLine("Main thread: Start a second thread.")
' The constructor for the Thread class requires a ThreadStart
' delegate. The Visual Basic AddressOf operator creates this
' delegate for you.
Dim t As New Thread(AddressOf ThreadProc)
' Start ThreadProc. Note that on a uniprocessor, the new
' thread does not get any processor time until the main thread
' is preempted or yields. Uncomment the Thread.Sleep that
' follows t.Start() to see the difference.
t.Start()
'Thread.Sleep(0)
Dim i As Integer
For i = 1 To 4
Console.WriteLine("Main thread: Do some work.")
Thread.Sleep(0)
Next
Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.")
t.Join()
Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program.")
Console.ReadLine()
End Sub
End Class
请参阅线程类:http:
//msdn.microsoft.com/en-us/library/system.threading.thread.aspx