Click here to Skip to main content
15,915,508 members
Home / Discussions / C#
   

C#

 
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 
smesser wrote:
Are you just banging this out for me or will you have an example to use the EventQueue class?


I may devote an article to it at some point. I'll definitely put it in the next version of my state machine toolkit for others to use.

Let's see if I can give you a quick example of using the EventQueue.

C#
public class MySystem
{
    private EventQueue eventQueue = new EventQueue();

    private MusicPlugin musicPlugin;

    public MySystem()
    {
        // Create events.
        eventQueue.CreateEvent("Play");
        eventQueue.CreateEvent("PlayingStopped");

        // Create music plugin and give it the event queue.
        musicPlugin = new MusicPlugin(eventQueue);

        // Subscribe to the playing stop event.
        eventQueue.Subscribe("PlayingStopped", new EventQueueEventHandler(HandlePlayingStopped);
    }

    private void HandlePlayingStopped(object sender, EventQueueEventArgs e)
    {
        // Logic for handling playing stopped event.
    }
}


Here, the system object handles an event sent to it from the music plugin telling the system that it has stopped playing.

Also, the system takes on the responsibility for creating all of the events before passing the event queue on to the plugin(s).

C#
public class MusicPlugin
{
    private EventQueue eventQueue;

    public MusicPlugin(EventQueue eventQueue)
    {
        this.eventQueue = eventQueue;

        eventQueue.Subscribe("Play", new EventQueueEventHandler(HandlePlayEvent));
    }

    private void HandlePlayEvent(object sender, EventQueueEventArgs e)
    {
        // Logic for starting playback.
    }

    public void StopPlaying()
    {
        eventQueue.Send("PlayingStopped", this, null);
    }
}


Now with an example this small, there's not much of an advantage here over using C#'s built in events. However, if you have a lot of plugins that are sending events to each other as well as to the system, this approach could help keep the plugins decoupled. You would have one central event queue for handling all of the event notification.
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 
GeneralRe: How do you implement a message queuing system? [modified] Pin
Steve Messer4-Jul-06 11:07
Steve Messer4-Jul-06 11:07 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford4-Jul-06 11:09
Leslie Sanford4-Jul-06 11:09 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer4-Jul-06 11:18
Steve Messer4-Jul-06 11:18 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford4-Jul-06 11:31
Leslie Sanford4-Jul-06 11:31 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer4-Jul-06 11:42
Steve Messer4-Jul-06 11:42 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford4-Jul-06 11:58
Leslie Sanford4-Jul-06 11:58 
GeneralRe: How do you implement a message queuing system? Pin
Steve Messer4-Jul-06 12:38
Steve Messer4-Jul-06 12:38 
GeneralRe: How do you implement a message queuing system? Pin
Leslie Sanford4-Jul-06 12:57
Leslie Sanford4-Jul-06 12:57 

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.