Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

MessageQueue.GetAllMessages Method

Returns all the messages that are in the queue.

Namespace:  System.Messaging
Assembly:  System.Messaging (in System.Messaging.dll)
public Message[] GetAllMessages()

Return Value

Type: System.Messaging.Message[]
An array of type Message that represents all the messages in the queue, in the same order as they appear in the Message Queuing queue.
ExceptionCondition
MessageQueueException

An error occurred when accessing a Message Queuing method.

GetAllMessages returns a static snapshot of the messages in the queue, not dynamic links to those messages. Therefore, you cannot use the array to modify the messages in the queue. If you want real-time, dynamic interaction with the queue (such as the ability to delete messages), call the GetMessageEnumerator2 method, which returns a dynamic list of the messages in the queue.

Because GetAllMessages returns a copy of the messages in the queue at the time the method was called, the array does not reflect new messages that arrive in the queue or messages that are removed from the queue.

GetAllMessages retrieves only those properties not filtered out by the MessageReadPropertyFilter property.

The following table shows whether this method is available in various Workgroup modes.

Workgroup mode

Available

Local computer

Yes

Local computer and direct format name

Yes

Remote computer

No

Remote computer and direct format name

Yes

The following code example demonstrates the use of GetAllMessages.


        // Connect to a queue on the local computer.
        MessageQueue queue = new MessageQueue(".\\exampleQueue");

        // Populate an array with copies of all the messages in the queue.
        Message[] msgs = queue.GetAllMessages();

        // Loop through the messages. 
        foreach(Message msg in msgs)
        {
            // Display the label of each message.
            Console.WriteLine(msg.Label);
        }

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.