The usual VB way to handle a computationally heavy task is to put it in a background worker thread, while the main thread keeps handling the UI.
Say for whatever reason I needed to do this the other way around: the main thread doing the grunt work and the background one updating the UI.
Here's what I have so far. The only problem is, while the UI window (Form1) does get redrawn, you can't interact with it, not even move or resize it (the mouse cursor turns to hourglass and won't click).
Public Class ProgressDisplay
Private trd As Thread
Public Sub New()
trd = New Thread(AddressOf threadtask)
trd.Start()
End Sub
Private Sub threadtask()
Dim f1 As Form1
f1 = New Form1
f1.Show()
Do
f1.Update()
Thread.Sleep(100)
Loop
End Sub
End Class
Edit: Ideally I need to present an interface like this to the client
Public Class ProgressDisplay
Public Sub New()
Public Sub Update(byval progress as int)
End Class
The client will call it like this (actually in unmanaged c++ over COM but you get the picture):
Dim prog = new ProgressDisplay()
DoLotsOfWork(addressof prog.update) ' DoLotsOfWork method takes a callback argument to keep client informed of progress
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…