VB.NET Threading or Backgroundworker ?? Struggling to get them to work

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 25
Reputation: poguemahone is an unknown quantity at this point 
Solved Threads: 2
poguemahone's Avatar
poguemahone poguemahone is offline Offline
Light Poster

Re: VB.NET Threading or Backgroundworker ?? Struggling to get them to work

 
0
  #11
Jan 27th, 2008
Ok,
What you want to do is create a Delegate Sub like this:

Delegate Sub LengthyProcessCallback()

In the beginning of the code for the event handler function add this:
 'Test to see if the correct thread is being used. If not, InvokeRequired will be true.

  If Me.lblFilename1.InvokeRequired Then
            'If InvokeRequired = True then this function will be re-called from the UI Thread.
            Dim d As New LengthyProcessCallback(AddressOf ThisFunction)
            Me.Invoke(d)
        Else
            Continue normal processing
        End If

I hope this makes more sense to you in the context of your app.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 16
Reputation: ads248 is an unknown quantity at this point 
Solved Threads: 0
ads248 ads248 is offline Offline
Newbie Poster

Re: VB.NET Threading or Backgroundworker ?? Struggling to get them to work

 
0
  #12
Jan 28th, 2008
Could yoo expand on that a little more. Sorry, I'm being realy dense with this.

Where doe the Delegate Sub....... need toi go in the code?

And the remainder of the code you have listed, where does that go and what do I need to replace ThisFunction with?

Incidently, my lengthy process is called LoadData and I tried raining the event FinishedDataLoading. But that's as far I got and then I had trouble with

Do you have a simple example?

Thanks for your help.

Andrew
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 25
Reputation: poguemahone is an unknown quantity at this point 
Solved Threads: 2
poguemahone's Avatar
poguemahone poguemahone is offline Offline
Light Poster

Re: VB.NET Threading or Backgroundworker ?? Struggling to get them to work

 
0
  #13
Jan 28th, 2008
The Delegate Sub can be put anywhere within the Class declaration, but not within another Sub or Function.

The name of the EventHandler Function should replace ThisFunction. In other words,
the name of the function that is being called when the Event is being raised.

The remainder of the code would go into the beginning of the EventHandler function like this:
Public Sub EventHandler()
'Test to see if the correct thread is being used. If not, InvokeRequired will be true.

  If Me.lblFilename1.InvokeRequired Then
            'If InvokeRequired = True then this function will be re-called from the UI Thread.
            Dim d As New LengthyProcessCallback(AddressOf ThisFunction)
            Me.Invoke(d)
        Else
         Place your code here from the EventHandler Function  
End If
End Sub
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum


Views: 10772 | Replies: 12
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC