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 ?
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.
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.
Re: Component has no Invoke or beginInvoke
Quote:
Originally Posted by
jmcilhinney
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
Re: Component has no Invoke or beginInvoke
Quote:
Originally Posted by
IanS
. . . .I'll go take a look right now and let you know.
Thanks
Ian
:wave: 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