Redigera

Dela via


MessageQueue Class

Definition

Provides access to a queue on a Message Queuing server.

public ref class MessageQueue : System::ComponentModel::Component, System::Collections::IEnumerable
[System.ComponentModel.TypeConverter(typeof(System.Messaging.Design.MessageQueueConverter))]
public class MessageQueue : System.ComponentModel.Component, System.Collections.IEnumerable
[System.ComponentModel.TypeConverter(typeof(System.Messaging.Design.MessageQueueConverter))]
[System.Messaging.MessagingDescription("MessageQueueDesc")]
public class MessageQueue : System.ComponentModel.Component, System.Collections.IEnumerable
[<System.ComponentModel.TypeConverter(typeof(System.Messaging.Design.MessageQueueConverter))>]
type MessageQueue = class
    inherit Component
    interface IEnumerable
[<System.ComponentModel.TypeConverter(typeof(System.Messaging.Design.MessageQueueConverter))>]
[<System.Messaging.MessagingDescription("MessageQueueDesc")>]
type MessageQueue = class
    inherit Component
    interface IEnumerable
Public Class MessageQueue
Inherits Component
Implements IEnumerable
Inheritance
Attributes
Implements

Examples

The following code example creates new MessageQueue objects using various path name syntax types. In each case, it sends a message to the queue whose path is defined in the constructor.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:

   // References public queues.
   void SendPublic()
   {
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );
      myQueue->Send( "Public queue by path name." );
      return;
   }


   // References private queues.
   void SendPrivate()
   {
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\Private$\\myQueue" );
      myQueue->Send( "Private queue by path name." );
      return;
   }


   // References queues by label.
   void SendByLabel()
   {
      MessageQueue^ myQueue = gcnew MessageQueue( "Label:TheLabel" );
      myQueue->Send( "Queue by label." );
      return;
   }


   // References queues by format name.
   void SendByFormatName()
   {
      MessageQueue^ myQueue = gcnew MessageQueue( "FormatName:Public=5A5F7535-AE9A-41d4 -935C-845C2AFF7112" );
      myQueue->Send( "Queue by format name." );
      return;
   }


   // References computer journal queues.
   void MonitorComputerJournal()
   {
      MessageQueue^ computerJournal = gcnew MessageQueue( ".\\Journal$" );
      while ( true )
      {
         Message^ journalMessage = computerJournal->Receive();
         
         // Process the journal message.
      }
   }


   // References queue journal queues.
   void MonitorQueueJournal()
   {
      MessageQueue^ queueJournal = gcnew MessageQueue( ".\\myQueue\\Journal$" );
      while ( true )
      {
         Message^ journalMessage = queueJournal->Receive();
         
         // Process the journal message.
      }
   }


   // References dead-letter queues.
   void MonitorDeadLetter()
   {
      MessageQueue^ deadLetter = gcnew MessageQueue( ".\\DeadLetter$" );
      while ( true )
      {
         Message^ deadMessage = deadLetter->Receive();
         
         // Process the dead-letter message.
      }
   }


   // References transactional dead-letter queues.
   void MonitorTransactionalDeadLetter()
   {
      MessageQueue^ TxDeadLetter = gcnew MessageQueue( ".\\XactDeadLetter$" );
      while ( true )
      {
         Message^ txDeadLetter = TxDeadLetter->Receive();
         
         // Process the transactional dead-letter message.
      }
   }

};


//*************************************************
// Provides an entry point into the application.
//         
// This example demonstrates several ways to set
// a queue's path.
//*************************************************
int main()
{
   
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;
   myNewQueue->SendPublic();
   myNewQueue->SendPrivate();
   myNewQueue->SendByLabel();
   myNewQueue->SendByFormatName();
   myNewQueue->MonitorComputerJournal();
   myNewQueue->MonitorQueueJournal();
   myNewQueue->MonitorDeadLetter();
   myNewQueue->MonitorTransactionalDeadLetter();
   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{
    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //		
        // This example demonstrates several ways to set
        // a queue's path.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            myNewQueue.SendPublic();
            myNewQueue.SendPrivate();
            myNewQueue.SendByLabel();
            myNewQueue.SendByFormatName();
            myNewQueue.MonitorComputerJournal();
            myNewQueue.MonitorQueueJournal();
            myNewQueue.MonitorDeadLetter();
            myNewQueue.MonitorTransactionalDeadLetter();

            return;
        }
        
        // References public queues.
        public void SendPublic()
        {
            MessageQueue myQueue = new MessageQueue(".\\myQueue");
            myQueue.Send("Public queue by path name.");

            return;
        }

        // References private queues.
        public void SendPrivate()
        {
            MessageQueue myQueue = new
                MessageQueue(".\\Private$\\myQueue");
            myQueue.Send("Private queue by path name.");

            return;
        }

        // References queues by label.
        public void SendByLabel()
        {
            MessageQueue myQueue = new MessageQueue("Label:TheLabel");
            myQueue.Send("Queue by label.");

            return;
        }

        // References queues by format name.
        public void SendByFormatName()
        {
            MessageQueue myQueue = new
                MessageQueue("FormatName:Public=5A5F7535-AE9A-41d4" +
                "-935C-845C2AFF7112");
            myQueue.Send("Queue by format name.");

            return;
        }

        // References computer journal queues.
        public void MonitorComputerJournal()
        {
            MessageQueue computerJournal = new
                MessageQueue(".\\Journal$");
            while(true)
            {
                Message journalMessage = computerJournal.Receive();
                // Process the journal message.
            }
        }

        // References queue journal queues.
        public void MonitorQueueJournal()
        {
            MessageQueue queueJournal = new
                MessageQueue(".\\myQueue\\Journal$");
            while(true)
            {
                Message journalMessage = queueJournal.Receive();
                // Process the journal message.
            }
        }
        
        // References dead-letter queues.
        public void MonitorDeadLetter()
        {
            MessageQueue deadLetter = new
                MessageQueue(".\\DeadLetter$");
            while(true)
            {
                Message deadMessage = deadLetter.Receive();
                // Process the dead-letter message.
            }
        }

        // References transactional dead-letter queues.
        public void MonitorTransactionalDeadLetter()
        {
            MessageQueue TxDeadLetter = new
                MessageQueue(".\\XactDeadLetter$");
            while(true)
            {
                Message txDeadLetter = TxDeadLetter.Receive();
                // Process the transactional dead-letter message.
            }
        }
    }
}
Imports System.Messaging

Public Class MyNewQueue


        
        ' Provides an entry point into the application.
        '		 
        ' This example demonstrates several ways to set
        ' a queue's path.
        

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue()

            myNewQueue.SendPublic()
            myNewQueue.SendPrivate()
            myNewQueue.SendByLabel()
            myNewQueue.SendByFormatName()
            myNewQueue.MonitorComputerJournal()
            myNewQueue.MonitorQueueJournal()
            myNewQueue.MonitorDeadLetter()
            myNewQueue.MonitorTransactionalDeadLetter()

            Return

        End Sub


        ' References public queues.
        Public Sub SendPublic()

            Dim myQueue As New MessageQueue(".\myQueue")
            myQueue.Send("Public queue by path name.")

            Return

        End Sub


        ' References private queues.
        Public Sub SendPrivate()

            Dim myQueue As New MessageQueue(".\Private$\myQueue")
            myQueue.Send("Private queue by path name.")

            Return

        End Sub


        ' References queues by label.
        Public Sub SendByLabel()

            Dim myQueue As New MessageQueue("Label:TheLabel")
            myQueue.Send("Queue by label.")

            Return

        End Sub


        ' References queues by format name.
        Public Sub SendByFormatName()

            Dim myQueue As New _
                MessageQueue("FormatName:Public=" + _
                    "5A5F7535-AE9A-41d4-935C-845C2AFF7112")
            myQueue.Send("Queue by format name.")

            Return

        End Sub


        ' References computer journal queues.
        Public Sub MonitorComputerJournal()

            Dim computerJournal As New MessageQueue(".\Journal$")

            While True

                Dim journalMessage As Message = _
                    computerJournal.Receive()

                ' Process the journal message.

            End While

            Return
        End Sub


        ' References queue journal queues.
        Public Sub MonitorQueueJournal()

            Dim queueJournal As New _
                            MessageQueue(".\myQueue\Journal$")

            While True

                Dim journalMessage As Message = _
                    queueJournal.Receive()

                ' Process the journal message.

            End While

            Return
        End Sub


        ' References dead-letter queues.
        Public Sub MonitorDeadLetter()
            Dim deadLetter As New MessageQueue(".\DeadLetter$")

            While True

                Dim deadMessage As Message = deadLetter.Receive()

                ' Process the dead-letter message.

            End While

            Return

        End Sub


        ' References transactional dead-letter queues.
        Public Sub MonitorTransactionalDeadLetter()

            Dim TxDeadLetter As New MessageQueue(".\XactDeadLetter$")

            While True

                Dim txDeadLetterMessage As Message = _
                    TxDeadLetter.Receive()

                ' Process the transactional dead-letter message.

            End While

            Return

        End Sub

End Class

The following code example sends a message to a queue, and receives a message from a queue, using an application-specific class called Order.

#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;

// This class represents an object the following example 
// sends to a queue and receives from a queue.
ref class Order
{
public:
   int orderId;
   DateTime orderTime;
};


/// <summary>
/// Provides a container class for the example.
/// </summary>
ref class MyNewQueue
{
public:

   //*************************************************
   // Sends an Order to a queue.
   //*************************************************
   void SendMessage()
   {
      // Create a new order and set values.
      Order^ sentOrder = gcnew Order;
      sentOrder->orderId = 3;
      sentOrder->orderTime = DateTime::Now;

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

      // Send the Order to the queue.
      myQueue->Send( sentOrder );
      return;
   }

   //*************************************************
   // Receives a message containing an Order.
   //*************************************************
   void ReceiveMessage()
   {
      // Connect to the a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

      // Set the formatter to indicate body contains an Order.
      array<Type^>^p = gcnew array<Type^>(1);
      p[ 0 ] = Order::typeid;
      myQueue->Formatter = gcnew XmlMessageFormatter( p );
      try
      {
         // Receive and format the message. 
         Message^ myMessage = myQueue->Receive();
         Order^ myOrder = static_cast<Order^>(myMessage->Body);

         // Display message information.
         Console::WriteLine( "Order ID: {0}", myOrder->orderId );
         Console::WriteLine( "Sent: {0}", myOrder->orderTime );
      }
      catch ( MessageQueueException^ ) 
      {
         // Handle Message Queuing exceptions.
      }
      // Handle invalid serialization format.
      catch ( InvalidOperationException^ e ) 
      {
         Console::WriteLine( e->Message );
      }

      // Catch other exceptions as necessary.
      return;
   }
};

//*************************************************
// Provides an entry point into the application.
//         
// This example sends and receives a message from
// a queue.
//*************************************************
int main()
{
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;

   // Send a message to a queue.
   myNewQueue->SendMessage();

   // Receive a message from a queue.
   myNewQueue->ReceiveMessage();
   return 0;
}
using System;
using System.Messaging;

namespace MyProject
{

    // This class represents an object the following example
    // sends to a queue and receives from a queue.
    public class Order
    {
        public int orderId;
        public DateTime orderTime;
    };	

    /// <summary>
    /// Provides a container class for the example.
    /// </summary>
    public class MyNewQueue
    {

        //**************************************************
        // Provides an entry point into the application.
        //		
        // This example sends and receives a message from
        // a queue.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Send a message to a queue.
            myNewQueue.SendMessage();

            // Receive a message from a queue.
            myNewQueue.ReceiveMessage();

            return;
        }

        //**************************************************
        // Sends an Order to a queue.
        //**************************************************
        
        public void SendMessage()
        {
            
            // Create a new order and set values.
            Order sentOrder = new Order();
            sentOrder.orderId = 3;
            sentOrder.orderTime = DateTime.Now;

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

            // Send the Order to the queue.
            myQueue.Send(sentOrder);

            return;
        }

        //**************************************************
        // Receives a message containing an Order.
        //**************************************************
        
        public  void ReceiveMessage()
        {
            // Connect to the a queue on the local computer.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");

            // Set the formatter to indicate body contains an Order.
            myQueue.Formatter = new XmlMessageFormatter(new Type[]
                {typeof(MyProject.Order)});
            
            try
            {
                // Receive and format the message.
                Message myMessage =	myQueue.Receive();
                Order myOrder = (Order)myMessage.Body;

                // Display message information.
                Console.WriteLine("Order ID: " +
                    myOrder.orderId.ToString());
                Console.WriteLine("Sent: " +
                    myOrder.orderTime.ToString());
            }
            
            catch (MessageQueueException)
            {
                // Handle Message Queuing exceptions.
            }

            // Handle invalid serialization format.
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
            
            // Catch other exceptions as necessary.

            return;
        }
    }
}
Imports System.Messaging

    ' This class represents an object the following example 
    ' sends to a queue and receives from a queue.
    Public Class Order
        Public orderId As Integer
        Public orderTime As DateTime
    End Class


   
    Public Class MyNewQueue


        '
        ' Provides an entry point into the application.
        '		 
        ' This example sends and receives a message from
        ' a qeue.
        '

        Public Shared Sub Main()

            ' Create a new instance of the class.
            Dim myNewQueue As New MyNewQueue()

            ' Send a message to a queue.
            myNewQueue.SendMessage()

            ' Receive a message from a queue.
            myNewQueue.ReceiveMessage()

            Return

        End Sub


        '
        ' Sends an Order to a queue.
        '

        Public Sub SendMessage()

            ' Create a new order and set values.
            Dim sentOrder As New Order()
            sentOrder.orderId = 3
            sentOrder.orderTime = DateTime.Now

            ' Connect to a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Send the Order to the queue.
            myQueue.Send(sentOrder)

            Return

        End Sub


        '
        ' Receives a message containing an Order.
        '

        Public Sub ReceiveMessage()

            ' Connect to the a queue on the local computer.
            Dim myQueue As New MessageQueue(".\myQueue")

            ' Set the formatter to indicate the body contains an Order.
            myQueue.Formatter = New XmlMessageFormatter(New Type() _
                {GetType(Order)})

            Try

                ' Receive and format the message. 
                Dim myMessage As Message = myQueue.Receive()
                Dim myOrder As Order = CType(myMessage.Body, Order)

                ' Display message information.
                Console.WriteLine(("Order ID: " + _
                    myOrder.orderId.ToString()))
                Console.WriteLine(("Sent: " + _
                    myOrder.orderTime.ToString()))

            Catch m As MessageQueueException
                ' Handle Message Queuing exceptions.

            Catch e As InvalidOperationException
                ' Handle invalid serialization format.
                Console.WriteLine(e.Message)


                ' Catch other exceptions as necessary.

            End Try

            Return

        End Sub

End Class

Remarks

The Message Queuing technology allows applications running at different times to communicate across heterogeneous networks and systems that might be temporarily offline. Applications send, receive, or peek (read without removing) messages from queues. Message Queuing is an optional component of Windows 2000 and Windows NT, and must be installed separately.

The MessageQueue class is a wrapper around Message Queuing. There are multiple versions of Message Queuing, and using the MessageQueue class can result in slightly different behavior, depending on the operating system you are using.

The MessageQueue class provides a reference to a Message Queuing queue. You can specify a path in the MessageQueue constructor to connect to an existing resource, or you can create a new queue on the server. Before you can call Send(Object), Peek, or Receive, you must associate the new instance of the MessageQueue class with an existing queue. At that point, you can manipulate the queue properties such as Category and Label.

MessageQueue supports two types of message retrieval: synchronous and asynchronous. The synchronous methods, Peek and Receive, cause the process thread to wait a specified time interval for a new message to arrive in the queue. The asynchronous methods, BeginPeek and BeginReceive, allow the main application tasks to continue in a separate thread until a message arrives in the queue. These methods work by using callback objects and state objects to communicate information between threads.

When you create a new instance of the MessageQueue class, you are not creating a new Message Queuing queue. Instead, you can use the Create(String), Delete(String), and Purge methods to manage queues on the server.

Unlike Purge, Create(String) and Delete(String) are static members, so you can call them without creating a new instance of the MessageQueue class.

You can set the MessageQueue object's Path property with one of three names: the friendly name, the FormatName, or the Label. The friendly name, which is defined by the queue's MachineName and QueueName properties, is MachineName\QueueName for a public queue, and MachineName\Private$\QueueName for a private queue. The FormatName property allows offline access to message queues. Lastly, you can use the queue's Label property to set the queue's Path.

For a list of initial property values for an instance of MessageQueue, see the MessageQueue constructor.

Constructors

MessageQueue()

Initializes a new instance of the MessageQueue class. After the parameterless constructor initializes the new instance, you must set the instance's Path property before you can use the instance.

MessageQueue(String, Boolean, Boolean, QueueAccessMode)

Initializes a new instance of the MessageQueue class.

MessageQueue(String, Boolean, Boolean)

Initializes a new instance of the MessageQueue class.

MessageQueue(String, Boolean)

Initializes a new instance of the MessageQueue class that references the Message Queuing queue at the specified path and with the specified read-access restriction.

MessageQueue(String, QueueAccessMode)

Initializes a new instance of the MessageQueue class.

MessageQueue(String)

Initializes a new instance of the MessageQueue class that references the Message Queuing queue at the specified path.

Fields

InfiniteQueueSize

Specifies that no size restriction exists for a queue.

InfiniteTimeout

Specifies that no time-out exists for methods that peek or receive messages.

Properties

AccessMode

Gets a value that indicates the access mode for the queue.

Authenticate

Gets or sets a value that indicates whether the queue accepts only authenticated messages.

BasePriority

Gets or sets the base priority Message Queuing uses to route a public queue's messages over the network.

CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
CanRead

Gets a value that indicates whether the MessageQueue can be read.

CanWrite

Gets a value that indicates whether the MessageQueue can be written to.

Category

Gets or sets the queue category.

Container

Gets the IContainer that contains the Component.

(Inherited from Component)
CreateTime

Gets the time and date that the queue was created in Message Queuing.

DefaultPropertiesToSend

Gets or sets the message property values to be used by default when the application sends messages to the queue.

DenySharedReceive

Gets or sets a value that indicates whether this MessageQueue has exclusive access to receive messages from the Message Queuing queue.

DesignMode

Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
EnableConnectionCache

Gets or sets a value that indicates whether a cache of connections will be maintained by the application.

EncryptionRequired

Gets or sets a value that indicates whether the queue accepts only non-private (non-encrypted) messages.

Events

Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
FormatName

Gets the unique queue name that Message Queuing generated at the time of the queue's creation.

Formatter

Gets or sets the formatter used to serialize an object into or deserialize an object from the body of a message read from or written to the queue.

Id

Gets the unique Message Queuing identifier of the queue.

Label

Gets or sets the queue description.

LastModifyTime

Gets the last time the properties of a queue were modified.

MachineName

Gets or sets the name of the computer where the Message Queuing queue is located.

MaximumJournalSize

Gets or sets the maximum size of the journal queue.

MaximumQueueSize

Gets or sets the maximum size of the queue.

MessageReadPropertyFilter

Gets or sets the property filter for receiving or peeking messages.

MulticastAddress

Introduced in MSMQ 3.0. Gets or sets the multicast address associated with the queue.

Path

Gets or sets the queue's path. Setting the Path causes the MessageQueue to point to a new queue.

QueueName

Gets or sets the friendly name that identifies the queue.

ReadHandle

Gets the native handle used to read messages from the message queue.

Site

Gets or sets the ISite of the Component.

(Inherited from Component)
SynchronizingObject

Gets or sets the object that marshals the event-handler call resulting from a ReceiveCompleted or PeekCompleted event.

Transactional

Gets a value that indicates whether the queue accepts only transactions.

UseJournalQueue

Gets or sets a value that indicates whether received messages are copied to the journal queue.

WriteHandle

Gets the native handle used to send messages to the message queue.

Methods

BeginPeek()

Initiates an asynchronous peek operation that has no time-out. The operation is not complete until a message becomes available in the queue.

BeginPeek(TimeSpan, Cursor, PeekAction, Object, AsyncCallback)

Initiates an asynchronous peek operation that has a specified time-out and that uses a specified cursor, a specified peek action, and a specified state object. The state object provides associated information throughout the lifetime of the operation. This overload receives notification, through a callback, of the identity of the event handler for the operation. The operation is not complete until either a message becomes available in the queue or the time-out occurs.

BeginPeek(TimeSpan, Object, AsyncCallback)

Initiates an asynchronous peek operation that has a specified time-out and a specified state object, which provides associated information throughout the operation's lifetime. This overload receives notification, through a callback, of the identity of the event handler for the operation. The operation is not complete until either a message becomes available in the queue or the time-out occurs.

BeginPeek(TimeSpan, Object)

Initiates an asynchronous peek operation that has a specified time-out and a specified state object, which provides associated information throughout the operation's lifetime. The operation is not complete until either a message becomes available in the queue or the time-out occurs.

BeginPeek(TimeSpan)

Initiates an asynchronous peek operation that has a specified time-out. The operation is not complete until either a message becomes available in the queue or the time-out occurs.

BeginReceive()

Initiates an asynchronous receive operation that has no time-out. The operation is not complete until a message becomes available in the queue.

BeginReceive(TimeSpan, Cursor, Object, AsyncCallback)

Initiates an asynchronous receive operation that has a specified time-out and uses a specified cursor and a specified state object. The state object provides associated information throughout the lifetime of the operation. This overload receives notification, through a callback, of the identity of the event handler for the operation. The operation is not complete until either a message becomes available in the queue or the time-out occurs.

BeginReceive(TimeSpan, Object, AsyncCallback)

Initiates an asynchronous receive operation that has a specified time-out and a specified state object, which provides associated information throughout the operation's lifetime. This overload receives notification, through a callback, of the identity of the event handler for the operation. The operation is not complete until either a message becomes available in the queue or the time-out occurs.

BeginReceive(TimeSpan, Object)

Initiates an asynchronous receive operation that has a specified time-out and a specified state object, which provides associated information throughout the operation's lifetime. The operation is not complete until either a message becomes available in the queue or the time-out occurs.

BeginReceive(TimeSpan)

Initiates an asynchronous receive operation that has a specified time-out. The operation is not complete until either a message becomes available in the queue or the time-out occurs.

ClearConnectionCache()

Clears the connection cache.

Close()

Frees all resources allocated by the MessageQueue.

Create(String, Boolean)

Creates a transactional or non-transactional Message Queuing queue at the specified path.

Create(String)

Creates a non-transactional Message Queuing queue at the specified path.

CreateCursor()

Creates a new Cursor for the current message queue.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Delete(String)

Deletes a queue on a Message Queuing server.

Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean)

Disposes of the resources (other than memory) used by the MessageQueue.

EndPeek(IAsyncResult)

Completes the specified asynchronous peek operation.

EndReceive(IAsyncResult)

Completes the specified asynchronous receive operation.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Exists(String)

Determines whether a Message Queuing queue exists at the specified path.

GetAllMessages()

Returns all the messages that are in the queue.

GetEnumerator()
Obsolete.

Enumerates the messages in a queue. GetEnumerator() is deprecated. GetMessageEnumerator2() should be used instead.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetMachineId(String)

Gets the identifier of the computer on which the queue referenced by this MessageQueue is located.

GetMessageEnumerator()
Obsolete.

Creates an enumerator object for all the messages in the queue. GetMessageEnumerator() is deprecated. GetMessageEnumerator2() should be used instead.

GetMessageEnumerator2()

Creates an enumerator object for all the messages in the queue.

GetMessageQueueEnumerator()

Provides forward-only cursor semantics to enumerate through all public queues on the network.

GetMessageQueueEnumerator(MessageQueueCriteria)

Provides forward-only cursor semantics to enumerate through all public queues on the network that meet the specified criteria.

GetPrivateQueuesByMachine(String)

Retrieves all the private queues on the specified computer.

GetPublicQueues()

Retrieves all the public queues on the network.

GetPublicQueues(MessageQueueCriteria)

Retrieves all the public queues on the network that meet the specified criteria.

GetPublicQueuesByCategory(Guid)

Retrieves all the public queues on the network that belong to the specified category.

GetPublicQueuesByLabel(String)

Retrieves all the public queues on the network that carry the specified label.

GetPublicQueuesByMachine(String)

Retrieves all the public queues that reside on the specified computer.

GetSecurityContext()

Retrieves the security context that MSMQ associates with the current user (thread identity) at the time of this call.

GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Peek()

Returns without removing (peeks) the first message in the queue referenced by this MessageQueue. The Peek() method is synchronous, so it blocks the current thread until a message becomes available.

Peek(TimeSpan, Cursor, PeekAction)

Returns without removing (peeks) the current or next message in the queue, using the specified cursor. The Peek() method is synchronous, so it blocks the current thread until a message becomes available or the specified time-out occurs.

Peek(TimeSpan)

Returns without removing (peeks) the first message in the queue referenced by this MessageQueue. The Peek() method is synchronous, so it blocks the current thread until a message becomes available or the specified time-out occurs.

PeekByCorrelationId(String, TimeSpan)

Peeks the message that matches the given correlation identifier and waits until either a message with the specified correlation identifier is available in the queue, or the time-out expires.

PeekByCorrelationId(String)

Peeks the message that matches the given correlation identifier and immediately raises an exception if no message with the specified correlation identifier currently exists in the queue.

PeekById(String, TimeSpan)

Peeks the message whose message identifier matches the id parameter. Waits until the message appears in the queue or a time-out occurs.

PeekById(String)

Peeks the message whose message identifier matches the id parameter.

PeekByLookupId(Int64)

Introduced in MSMQ 3.0. Peeks at the message that matches the given lookup identifier from a non-transactional queue.

PeekByLookupId(MessageLookupAction, Int64)

Introduced in MSMQ 3.0. Peeks at a specific message from the queue. The message can be specified by a lookup identifier or by its position at the front or end of the queue.

Purge()

Deletes all the messages contained in the queue.

Receive()

Receives the first message available in the queue referenced by the MessageQueue. This call is synchronous, and blocks the current thread of execution until a message is available.

Receive(MessageQueueTransaction)

Receives the first message available in the transactional queue referenced by the MessageQueue. This call is synchronous, and blocks the current thread of execution until a message is available.

Receive(MessageQueueTransactionType)

Receives the first message available in the queue referenced by the MessageQueue. This call is synchronous, and blocks the current thread of execution until a message is available.

Receive(TimeSpan, Cursor, MessageQueueTransaction)

Receives the current message in the queue, using a specified cursor. If no message is available, this method waits until either a message is available, or the time-out expires.

Receive(TimeSpan, Cursor, MessageQueueTransactionType)

Receives the current message in the queue, using a specified cursor. If no message is available, this method waits until either a message is available, or the time-out expires.

Receive(TimeSpan, Cursor)

Receives the current message in the queue, using a specified cursor. If no message is available, this method waits until either a message is available, or the time-out expires.

Receive(TimeSpan, MessageQueueTransaction)

Receives the first message available in the transactional queue referenced by the MessageQueue and waits until either a message is available in the queue, or the time-out expires.

Receive(TimeSpan, MessageQueueTransactionType)

Receives the first message available in the queue referenced by the MessageQueue. This call is synchronous, and waits until either a message is available in the queue, or the time-out expires.

Receive(TimeSpan)

Receives the first message available in the queue referenced by the MessageQueue and waits until either a message is available in the queue, or the time-out expires.

ReceiveByCorrelationId(String, MessageQueueTransaction)

Receives the message that matches the given correlation identifier (from a transactional queue) and immediately raises an exception if no message with the specified correlation identifier currently exists in the queue.

ReceiveByCorrelationId(String, MessageQueueTransactionType)

Receives the message that matches the given correlation identifier and immediately raises an exception if no message with the specified correlation identifier currently exists in the queue.

ReceiveByCorrelationId(String, TimeSpan, MessageQueueTransaction)

Receives the message that matches the given correlation identifier (from a transactional queue) and waits until either a message with the specified correlation identifier is available in the queue, or the time-out expires.

ReceiveByCorrelationId(String, TimeSpan, MessageQueueTransactionType)

Receives the message that matches the given correlation identifier and waits until either a message with the specified correlation identifier is available in the queue, or the time-out expires.

ReceiveByCorrelationId(String, TimeSpan)

Receives the message that matches the given correlation identifier (from a non-transactional queue) and waits until either a message with the specified correlation identifier is available in the queue, or the time-out expires.

ReceiveByCorrelationId(String)

Receives the message that matches the given correlation identifier (from a non-transactional queue) and immediately raises an exception if no message with the specified correlation identifier currently exists in the queue.

ReceiveById(String, MessageQueueTransaction)

Receives the message that matches the given identifier (from a transactional queue) and immediately raises an exception if no message with the specified identifier currently exists in the queue.

ReceiveById(String, MessageQueueTransactionType)

Receives the message that matches the given identifier and immediately raises an exception if no message with the specified identifier currently exists in the queue.

ReceiveById(String, TimeSpan, MessageQueueTransaction)

Receives the message that matches the given identifier (from a transactional queue) and waits until either a message with the specified identifier is available in the queue or the time-out expires.

ReceiveById(String, TimeSpan, MessageQueueTransactionType)

Receives the message that matches the given identifier and waits until either a message with the specified identifier is available in the queue or the time-out expires.

ReceiveById(String, TimeSpan)

Receives the message that matches the given identifier (from a non-transactional queue) and waits until either a message with the specified identifier is available in the queue or the time-out expires.

ReceiveById(String)

Receives the message that matches the given identifier from a non-transactional queue and immediately raises an exception if no message with the specified identifier currently exists in the queue.

ReceiveByLookupId(Int64)

Introduced in MSMQ 3.0. Receives the message that matches the given lookup identifier from a non-transactional queue.

ReceiveByLookupId(MessageLookupAction, Int64, MessageQueueTransaction)

Introduced in MSMQ 3.0. Receives a specific message from a transactional queue. The message can be specified by a lookup identifier or by its position at the front or end of the queue.

ReceiveByLookupId(MessageLookupAction, Int64, MessageQueueTransactionType)

Introduced in MSMQ 3.0. Receives a specific message from the queue, using the specified transaction context. The message can be specified by a lookup identifier or by its position at the front or end of the queue.

Refresh()

Refreshes the properties presented by the MessageQueue to reflect the current state of the resource.

ResetPermissions()

Resets the permission list to the operating system's default values. Removes any queue permissions you have appended to the default list.

Send(Object, MessageQueueTransaction)

Sends an object to the transactional queue referenced by this MessageQueue.

Send(Object, MessageQueueTransactionType)

Sends an object to the queue referenced by this MessageQueue.

Send(Object, String, MessageQueueTransaction)

Sends an object to the transactional queue referenced by this MessageQueue and specifies a label for the message.

Send(Object, String, MessageQueueTransactionType)

Sends an object to the queue referenced by this MessageQueue and specifies a label for the message.

Send(Object, String)

Sends an object to the non-transactional queue referenced by this MessageQueue and specifies a label for the message.

Send(Object)

Sends an object to non-transactional queue referenced by this MessageQueue.

SetPermissions(AccessControlList)

Assigns access rights to the queue based on the contents of an access control list.

SetPermissions(MessageQueueAccessControlEntry)

Assigns access rights to the queue based on the contents of an access control entry.

SetPermissions(String, MessageQueueAccessRights, AccessControlEntryType)

Gives a computer, group, or user the specified access rights, with the specified access control type (allow, deny, revoke, or set).

SetPermissions(String, MessageQueueAccessRights)

Gives a computer, group, or user the specified access rights.

ToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.

(Inherited from Component)

Events

Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
PeekCompleted

Occurs when a message is read without being removed from the queue. This is a result of the asynchronous operation, BeginPeek().

ReceiveCompleted

Occurs when a message has been removed from the queue. This event is raised by the asynchronous operation, BeginReceive().

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

Thread Safety

Only the GetAllMessages() method is thread safe.

See also