Επεξεργασία

Κοινή χρήση μέσω


MessageQueue.GetAllMessages Method

Definition

Returns all the messages that are in the queue.

public:
 cli::array <System::Messaging::Message ^> ^ GetAllMessages();
public System.Messaging.Message[] GetAllMessages ();
member this.GetAllMessages : unit -> System.Messaging.Message[]
Public Function GetAllMessages () As Message()

Returns

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.

Exceptions

An error occurred when accessing a Message Queuing method.

Examples

The following code example demonstrates the use of GetAllMessages.


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

// Populate an array with copies of all the messages in the queue.
array<Message^>^ msgs = queue->GetAllMessages();

// Loop through the messages.
for each(Message^ msg in msgs)
{
    // Display the label of each message.
    Console::WriteLine(msg->Label);
}

queue->Close();

// 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);
}

Remarks

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

Applies to

See also