views:

238

answers:

1

Hi!

C#: i use the Message Queue to send messages from one application to the other one (this has to work only on one particular machine)

I create the queu like this on the receiver side:

        string queueName = ".\\private$\\WZMSGQ";
        if (MessageQueue.Exists(queueName))
            msgQueue = new MessageQueue(queueName);
        else
            msgQueue = MessageQueue.Create(queueName, false);

and after this i start the sender application, where i create the queue like that:

        msgQueue = new MessageQueue(".\\private$\\WZMSGQ");

in the receiver Application I then retrieve new messages:

        Message[] messages = msgQueue.GetAllMessages();
        foreach (Message msg in messages){
             doSomething();
        }

Now i'd like to do two things:

I would like to clear the message queue when instanciating the new MessageQueue instance on the receiver machine such that all old messages are gone. I'd like to delete the message queue when the program ends, such that it does not exist anymore if i start the application the next time

how can I do that?

Thanks!

+1  A: 

MessageQueue.Purge and MessageQueue.Delete seem to be what you want, unless I have misread the question.

ZombieSheep