943,650 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 17747
  • VB.NET RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jan 27th, 2008
0

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

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.
Reputation Points: 13
Solved Threads: 2
Light Poster
poguemahone is offline Offline
25 posts
since Aug 2007
Jan 28th, 2008
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ads248 is offline Offline
16 posts
since Jan 2008
Jan 28th, 2008
0

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

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
Reputation Points: 13
Solved Threads: 2
Light Poster
poguemahone is offline Offline
25 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Randomize A Chosen
Next Thread in VB.NET Forum Timeline: Enable Menu items





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC