Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Invoke question when dealing with multiple threads
Xref: newsfeed-west.nntpserver.com microsoft.public.dotnet.csharp.general:46
60 microsoft.public.dotnet.languages.csharp:414909

I am creating a pub/sub broker implementation in C# and I am having some
trouble understanding how I should best implement the invoke portion in
order to make sure it is as thread-safe as it can be.

The "broker" class allows other objects to subscribe to messages that will
get published by other objects.  To subscribe they pass in a Object that
represents thier instance (aka 'this') and a String that contains the method
name to be invoked.  When a particular message is published the instance and
method name are used to forward the message (and any data that was sent with
it) to the subscriber so they can process it.  Each message may have zero or
more subscribers as well.

To process the queued messages I am using a System.Timers.Timer class which
uses a separate thread to handle the delay between the timer events.  Inside
the Timer elapsed event I am forwarding all of the queued messages to any
subscribers that are interrested in them.

To perform the Invoke I am doing the following which I believe will cause
problems.

Instance.GetType().GetMethod(MethodName).Invoke(Instance, Parms);

Where Instance is an Object that the subscriber passed in (aka 'this'),
MethodName is a String that contains a public method to be invoked, and
Parms is a Object[] that contains the parameters that the method is
expecting.

How thread-safe is this since there are at least 2 threads being used
(whatever the application thread is and the Timer thread.)  I will not know
ahead of time what the subscriber actually is - plain class, WinForms class,
etc.

I have seen mention of ISynchronizeInvoke, Invoke, BeginInvoke and EndInvoke
but I am not sure exactly how they play into this sort of environment.

Any suggestions or input would be appreciated.

Chuck




Report this thread to moderator Post Follow-up to this message
Old Post
Chuck
05-14-05 09:04 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C# archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:14 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.