Click here to Skip to main content
15,912,069 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer24-Jun-06 15:00
Steve Messer24-Jun-06 15:00 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford24-Jun-06 19:55
Leslie Sanford24-Jun-06 19:55 
GeneralRe: How do you implement a message queuing system? [modified] Pin
Steve Messer24-Jun-06 20:15
Steve Messer24-Jun-06 20:15 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford24-Jun-06 21:11
Leslie Sanford24-Jun-06 21:11 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer25-Jun-06 3:47
Steve Messer25-Jun-06 3:47 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford25-Jun-06 5:35
Leslie Sanford25-Jun-06 5:35 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer25-Jun-06 5:54
Steve Messer25-Jun-06 5:54 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford25-Jun-06 6:27
Leslie Sanford25-Jun-06 6:27 
smesser wrote:
Thanks for the dialog as it is more helpful than you realize. You make me think about this in
ways that I may overlook. It's always nice to bouce idea around.


I'm glad it's helpful. Smile | :) It's got me thinking, too.

I think the messaging you've described may be complex enough that using C# events may not be appropriate. It could become a kind of a tangled mess to pass around plugins so that other objects can subscribe to their events.

You mentioned the MessageQueue class in your original post. I think you were on the right track to begin with. Maybe you need a class that provides that type of functionality for your application, but as you say the MessageQueue class isn't exactly what you're looking for.

So how about one that's designed for local communication instead?

Here's my idea of what the methods for this class could look like, let's call it EventQueue to avoid clashing with the .NET's MessageQueue class:

Methods:

C#
void CreateEvent(string eventName);

void Subscribe(string eventName, SendOrPostCallback callback);

void Unsubscribe(string eventName, SendOrPostCallback callback);

void Send(string eventName, object state);


Ok, here's it works: The CreateEvent method creates an event (not in the C# sense, just in the general sense) with the specified event name. After this event is created, those objects, in this case the plugins and the system, can subscribe to the event with the Subscribe method and unsubscribe with the Unsubscribe method.

When one object needs to send an event, it calls the Send method, specifying the event name. It also passes along an object representing the information about that event. The EventQueue then looks up all of the subscribers for that event and calls the SendOrPostCallback delegate for each subscriber, passing along the state object that was passed to Send.

The receivers of any event will need to know how to unpack the state object passed to Send. This object could be null if no additional information is needed for the event, or it could represent some object that has all the details the receivers need to understand the event.

Each plugin as well as the system would have access to an EventQueue for sending and receiving events. Care would need to be taken so that senders and receivers can understand each other. In other words, they would have to agree to a protocol as far as event names and their accompanying information, if any.

The EventQueue class would run in its own thread, so events would need to be marshalled from one thread to another. There are ways that the EventQueue could do this itself, but I won't go into that here; this has already turned into a long post. Smile | :)

I'm thinking of writing this class, actually. It wouldn't be hard using my DelegateQueue class to provide most of the functionality. I might find an EventQueue class useful myself.

Let me know what you think of this approach.
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer25-Jun-06 7:46
Steve Messer25-Jun-06 7:46 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford25-Jun-06 8:24
Leslie Sanford25-Jun-06 8:24 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer25-Jun-06 8:56
Steve Messer25-Jun-06 8:56 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford25-Jun-06 9:16
Leslie Sanford25-Jun-06 9:16 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer25-Jun-06 12:35
Steve Messer25-Jun-06 12:35 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford25-Jun-06 13:20
Leslie Sanford25-Jun-06 13:20 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer25-Jun-06 13:37
Steve Messer25-Jun-06 13:37 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford25-Jun-06 13:48
Leslie Sanford25-Jun-06 13:48 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer25-Jun-06 14:20
Steve Messer25-Jun-06 14:20 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford25-Jun-06 15:17
Leslie Sanford25-Jun-06 15:17 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer25-Jun-06 18:08
Steve Messer25-Jun-06 18:08 
GeneralRe: How do you implement a message queuing system? [modified] Pin
Leslie Sanford26-Jun-06 5:18
Leslie Sanford26-Jun-06 5:18 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer26-Jun-06 7:22
Steve Messer26-Jun-06 7:22 
GeneralRe: How do you implement a message queuing system? [modified] Pin
Steve Messer4-Jul-06 8:44
Steve Messer4-Jul-06 8:44 
AnswerRe: How do you implement a message queuing system? Pin
Leslie Sanford27-Jun-06 6:08
Leslie Sanford27-Jun-06 6:08 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer27-Jun-06 6:31
Steve Messer27-Jun-06 6:31 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford4-Jul-06 8:56
Leslie Sanford4-Jul-06 8:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.