467,921 Members | 1,302 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,921 developers. It's quick & easy.

Form.Label.Invoke method not working

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("Openin g"))
Extract(filename)

filename.Open

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

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

UploadForm.Label.Invoke(UpdateField.Invoke("Finish ed
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
Jul 19 '05 #1
  • viewed: 3689
Share:
1 Reply
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"
-----Original Message-----
Here is my basic problem. I have a form that executes acpu instensive algorithm occupying the first thread. Whenthe algorithm is executed another form pops up telling theuser the progress that has been made.
Whenever I attempt to update my frmProgress, the eventsare 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 reacha 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 ("ExtractingText from file"))
Dim str As String = GetText(filename)

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

UploadForm.Label.Invoke(UpdateField.Invoke("Finish ed
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
.

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Skippytpe | last post: by
10 posts views Thread by Drakier Dominaeus | last post: by
4 posts views Thread by Venus | last post: by
reply views Thread by Venus | last post: by
1 post views Thread by John Altland | last post: by
7 posts views Thread by ChrisM | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.