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

C#

 
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 
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 
smesser wrote:
Now this is really getting exciting... Programming is exciting right ????


Yeah, this is fun stuff. Big Grin | :-D

Since posting, I've already banging out most of an EventQueue class for fun. I'll get into the details in a moment. Smile | :)

smesser wrote:
One thing is starting to get a little fuzzy for me. That is the difference betweek a message and an event. I have been kind of picturing them as one in the same.


Same here. I use event and message interchangeably. I guess if we really wanted to nail down a definition, we could say that an event is something that happens, and a message is the information that accompanies the event. But honestly, I use them both to mean the same thing.

Let me run through how the EventQueue class can be used, and we'll see where your approach and mine can meet.

First, create an EventQueue and also create an event.

C#
EventQueue eventQueue = new EventQueue();
int endOfSongEventID = eventQueue.CreateEvent("EndOfSong");


Now, subscribers can subscribe to this event. The EventQueue can provide a list of all of the events available on demand.

Next, in some other object, we subscribe to the "EndOfSong" event.

C#
eventQueue.Subscribe("EndOfSong", new EventQueueEventHandler(HandleEndOfSong));


The second argument is a delegate to the method that will handle the "EndOfSong" event. It looks like this:

C#
private void HandleEndOfSong(object sender, EventQueueEventArgs e)
{
    // Do stuff in response to EndOfSong event.
}


The EventQueueEventArgs class is a class representing information about any event raised by the EventQueue.

So somewhere else in our code, whereever the EndOfSong event originates, we send an event to our EventQueue:

C#
eventQueue.Send(endOfSongEventID, this, null);


The endOfSongEventID is the integer value returned when we first created the event. So instead of passing the event name when we send an event, we use the integer event ID. This is more efficient for the EventQueue to deal with.

At some point later in time, the EventQueue dequeues the event and notifies all of the subscribers that have subscribed to that event.
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 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer4-Jul-06 9:53
Steve Messer4-Jul-06 9:53 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford4-Jul-06 10:15
Leslie Sanford4-Jul-06 10:15 

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.