Form.Label.Invoke method not working

  • Thread starter Thread starter John Altland
  • Start date Start date
J

John Altland

Here is my basic problem. I have a form that executes a
cpu instensive algorithm occupying the first thread. When
the algorithm is executed another form pops up telling the
user the progress that has been made.
Whenever I attempt to update my frmProgress, the events
are put placed at the end of the thread's queue and
executed after my algorithm is finished. Using the
frmProgress.Label.Invoke method with delagates, I have
heard would fix this problem, however I have yet to reach
a resolution. Can anyone help me out. Here is the code.

Delegate Sub UpdateDelegate(ByVal updatefield As String)
Delegate Sub PaintForm()
Public Sub TextExtractor
Dim UploadForm As New UploadConfirm
Dim UpdateField As UpdateDelegate
Dim PF As PaintForm
PF = AddressOf UploadForm.Show
PF.Invoke()
UpdateField = AddressOf UploadForm.UpdateLabel
UploadForm.Label.Invoke(UpdateField.Invoke("Opening"))
Extract(filename)

filename.Open

UploadForm.Label.Invoke(UpdateField.Invoke("Extracting
Text from file"))
Dim str As String = GetText(filename)

UploadForm.Label.Invoke(UpdateField.Invoke("Sending
Text to Database") )
SendToDB(str)

UploadForm.Label.Invoke(UpdateField.Invoke("Finished
Uploading File"))
filename.Close
End Sub
.....
End Class

Class UploadConfirm
....
Public Sub UpdateLabel(ByVal str As String)
Me.Label.Text = str
End Sub
....
End Class

Thanks for any help
 
Since this is only a snippet of code, I can't tell if
you've put this together the right way. But, the standard
way of working with threads and the UI is to use a
Worker - Controller - Client pattern. To see a great
example of this and a good explanation, look at Rocky
Lhotka's article on MSDN:
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dnadvnet/html/vbnet09272002.asp

Using this example should do the trick for you.

Jeff Levinson

Author of "Building Client/Server Applications with
VB.NET: An Example Driven Approach"
 
Back
Top