Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Component with threads

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve Whine - 08 Apr 2005 13:09 GMT
Hello,

I am writing a Component whose work needs to be done on a separate
thread (or ThreadPool), and when this work is done a Component event
needs to be fired in the main GUI thread. What is the best way to send a
mesasge to this Component?

As far as I can see, here are my options, in order from least appealing
to most appealing:

1) Make my Component a Control so I can use Control.Invoke. I don't like
this idea, my control does not need to be visible at runtime.

2) Use Application.Forms and call Invoke on one of those forms. This
means that the Component won't work if someone tries to use it in a
window-less app.

3) Create a static hidden message window with my component. What would
be the best way to do that? There is a MessageWindow class but it seems
to be limited to the compact framework.

If anyone can help, please let me know!

Cheers
Steve
Jon Skeet [C# MVP] - 08 Apr 2005 20:28 GMT
> I am writing a Component whose work needs to be done on a separate
> thread (or ThreadPool), and when this work is done a Component event
[quoted text clipped - 14 lines]
> be the best way to do that? There is a MessageWindow class but it seems
> to be limited to the compact framework.

If you already *have* a UI thread, chances are you've got at least *a*
control visible - pass that (as an ISynchronizeInvoke) to the object
doing the work.

If you aren't guaranteeing that you've got a UI thread, you need to
have something running a message pump or something similar - a
producer/consumer queue could quite possibly do what you want. See half
way down
http://www.pobox.com/~skeet/csharp/threads/deadlocks.shtml

You could provide an API which allows the user to specify an
ISynchronizeInvoke to use, so they can do the most appropriate thing to
their situation, either passing in a control or possibly their own
implementation which uses something like the queue above if necessary.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Steve Whine - 13 Apr 2005 11:00 GMT
>>I am writing a Component whose work needs to be done on a separate
>>thread (or ThreadPool), and when this work is done a Component event
[quoted text clipped - 29 lines]
> their situation, either passing in a control or possibly their own
> implementation which uses something like the queue above if necessary.

Thank you Jon, I had not come across ISynchronizeInvoke, I will look
into it.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.