|
-
Sep 18th, 2005, 02:14 AM
#1
Thread Starter
Frenzied Member
[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)
-
Sep 18th, 2005, 03:32 AM
#2
Re: Automatic Thread switching using delegates and the UI thread
-
Sep 19th, 2005, 08:40 AM
#3
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|