By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,576 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

Form.Label.Invoke method not working

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.