Results 1 to 3 of 3

Thread: [RESOLVED] Automatic Thread switching using delegates and the UI thread

  1. #1

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Resolved [RESOLVED] Automatic Thread switching using delegates and the UI thread

    I'm still trying to learn the concepts of delegates and stuff, but I think I've got it going alright, my problem is when I have to switch to the UI thread.

    I've read all the rules for theads such as the one that says "thou shalt not reference controls on the form's thread from a secondary thread" (or something along them lines) and I can do that. I know how to use the Me.InvokeRequired property to check that I'm on the required thread etc.

    The problem is when I try to encapsulate a bunch of methods and expose methods that allow the calling code to either run synchronously or asynchronously. Because I use events to allow the calling object to update the UI with the progress, the events are raised and executed on the secondary thread and require switching. This is annoying because every event then inturn requires a delegate to be created by the calling method and then the UI thread needs to be invoked to update the UI.

    How can I get my class to do all this automatically, much like the BackgroundWorker control does in Visual Studio 2005? i.e. When my events are raised, they are invoked on the UI's thread, not the secondary thread.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Automatic Thread switching using delegates and the UI thread

    You might find this thread helpful:
    http://www.vbforums.com/showthread.php?t=358683

  3. #3

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Re: Automatic Thread switching using delegates and the UI thread

    Thankyou very much Edneeis, worked like a charm.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width