Initializes a new instance of the MessageQueue class. To use the object instantiated by the default constructor, the Path property must be set.
[Visual Basic] Overloads Public Sub New() [C#] public MessageQueue(); [C++] public: MessageQueue(); [JScript] public function MessageQueue();
Exception Type | Condition |
---|---|
ArgumentException | The Path property syntax in invalid. The path may not have been set. |
MessageQueueException | The FormatName property is invalid. |
MessageQueueException | The application attempted to access a queue defined by its Path property while offline. |
The MessageQueue constructor instantiates a new instance of a MessageQueue class. The constructor does not create a new Message Queuing object, so the queue to which you link the MessageQueue must already exist. To create a new queue in Message Queuing, use Create.
Use this overloaded constructor when you want to create a new MessageQueue but do not want to tie it immediately to a Message Queuing backend object. Before using the object instantiated by this overload, you must set the Path property to connect to an existing Message Queuing queue. Alternately, you can use Create to create a new backend queue object by setting the MessageQueue instance to the return value of the Create method.
When an instance of MessageQueue is created, the following read/write properties are set to initial values.
Property | Initial Value |
---|---|
DefaultPropertiesToSend | The values set by the default constructor of the DefaultPropertiesToSend class. |
Formatter | ?? XmlQueueMessageFormatter |
MessageReadPropertyFilter | The values set by the default constructor of the MessagePropertyFilter class. All filter values are set to true. |
DenySharedReceive | false |
You can change the value for any of these properties through a separate call to the property.
The following example creates a new MessageQueue object and sends a message to the queue.
This example assumes that there is a body (say, a text string) passed into the procedure. It also assumes there is a Message Queuing computer named myComputer and a queue on that computer called myQueue.
Import the System.Messaging namespace for this example.
[Visual Basic]
Private Sub SendMessage(ByVal body As Object) 'Create a new MessageQueue object. Dim mq As MessageQueue 'Initialize the MessageQueue object using the constructor. mq = New MessageQueue 'Set the queue path to an existing queue. mq.Path = "myComputer\myQueue" 'Send a message to the queue. mq.Send(body) End Sub
MessageQueue Class | MessageQueue Members | System.Messaging Namespace | MessageQueue Constructor Overload List | Create | Path | FormatName