Results 1 to 5 of 5

Thread: Component has no Invoke or beginInvoke

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Component has no Invoke or beginInvoke

    I have a component which starts a secondary thread.

    I don't want the main thread to loop, poll or wait for the secondary thread to finish. I want an event to be fired when the secondary thread is finished.

    If the main thread was a ui or a control then the secondary thread could use BeginInvoke to fire an event in the main thread.

    But Component doesn't have any Invoke or beginInvoke so I can't do that.

    How does the secondary thread fire an event in the main thread of the component ?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Component has no Invoke or beginInvoke

    Follow the CodeBank link in my signature and check out my Asynchronous TCP submission. The project attached to the first post uses the SynchronizationContext class. There's another version attached to a later post that uses the ISynchronizeInvoke interface (which is where Invoke, etc come from) in much the same way as the Timers.Timer and FileSystemWatcher classes do.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Component has no Invoke or beginInvoke

    Ooh... just realised I'm in the C# forum and I haven't created a C# version of that project. I'd suggest checking out the Vb version as you should still be able to work out what's going on. I'll look at creating a C# version of that project tomorrow.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: Component has no Invoke or beginInvoke

    Quote Originally Posted by jmcilhinney View Post
    Ooh... just realised I'm in the C# forum and I haven't created a C# version of that project. I'd suggest checking out the Vb version as you should still be able to work out what's going on. I'll look at creating a C# version of that project tomorrow.
    The language isn't a problem for me - I'll go take a look right now and let you know.

    Thanks
    Ian

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    Re: Component has no Invoke or beginInvoke

    Quote Originally Posted by IanS View Post

    . . . .I'll go take a look right now and let you know.

    Thanks
    Ian
    SynchronizationContext was the solution. Thank you !!

    I've been googleing this problem for ages and all the results went on about delagates and events and all manner of convoluted hacks. Your SynchronizationContext did it in just two lines of code. I like an easy solution.

    Thank you
    Ian

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