1

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 queue 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 instantiating 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?

1 Answer 1

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.