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.




Reply With Quote