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 / February 2007

Tip: Looking for answers? Try searching our database.

raising events via "Invoke" - good pattern? - or not....

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oli - 05 Feb 2007 13:52 GMT
Hi - I am communicating with my UI thread using the following
technique. This has appalled one of my co-workers ;) - any comments
about it's brilliantness or lack thereof welcome.....

two threads:
  1) UI thread
  2) Worker thread

- something happens in the worker thread - I need to update the UI.
- worker thread exposes an event - UI thread wires an event handler
into that event
- when worker thread needs something to happen - it raises the event

*** but for the event handler to run on the UI thread - the worker
thread raises the event (via "Invoke") ***

I like this because the UI thread code needs to simply wire up an
event handler. There is hence good separation between the code running
the UI, and the code running the Worker thread.

O.
Brian Gideon - 05 Feb 2007 15:41 GMT
> Hi - I am communicating with my UI thread using the following
> technique. This has appalled one of my co-workers ;) - any comments
[quoted text clipped - 17 lines]
>
> O.

Hi,

I don't know why that would appall your coworker.  It sounds similar
to the pattern Microsoft used with System.Timers.Timer and the
SynchronizingObject property.

Brian
Stoitcho Goutsev (100) - 06 Feb 2007 15:46 GMT
Oli,

I'd suggest to follow the design pattern of classes like
System.Timers.Timer. Those components have property called
SynchronizingObject of type ISynchronizeInvoke. If the user sets this
proeprty then the event raising code should use the sync object to invoke
the event handlers other wise ot raises the event handler directly. This way
the user can chose whether he/she wants to handle the event in the context
of the worker thread or the UI thread.
ISynchronizeInvoke is implemented by the Control class, so if the user
provides referenc to a control it basically works in the same way as you
call Control.Invoke, thus marshaling the event handler to the UI thread.

Signature

HTH
Stoitcho Goutsev (100)

> Hi - I am communicating with my UI thread using the following
> technique. This has appalled one of my co-workers ;) - any comments
[quoted text clipped - 17 lines]
>
> O.

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.