MessageQueue.Create Method (String)
Creates a nontransactional Message Queuing queue at the specified path.
[Visual Basic] Overloads Public Shared Function Create( _ ByVal path As String _ ) As MessageQueue [C#] public static MessageQueue Create( string path ); [C++] public: static MessageQueue* Create( String* path ); [JScript] public static function Create( path : String ) : MessageQueue;
Parameters
- path
- The path of the queue to create.
Return Value
A MessageQueue that represents the new queue.
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentException | The path parameter is a null reference (Nothing in Visual Basic) or is an empty string (""). |
| MessageQueueException | A queue already exists at the specified path.
-or- An error occurred when accessing a Message Queuing API. |
Remarks
Use this overload to create a nontransactional Message Queuing queue.
To create a new instance of the MessageQueue class in your application and bind it to an existing queue, use the MessageQueue constructor. To create a new queue in Message Queuing, call Create.
The syntax for the path parameter depends on the type of queue it references.
| Queue Type | Syntax |
|---|---|
| Public queue | MachineName\ QueueName |
| Private queue | MachineName\Private$\ QueueName |
Use "." for the local computer. For more syntax, see the Path property.
The following table shows whether this method is available in various Workgroup modes.
| Workgroup Mode | Available |
|---|---|
| Local computer | No |
| Local computer + direct format name | No |
| Remote computer | No |
| Remote computer + direct format name | No |
Example
[Visual Basic, C#, C++] The following example creates public and private queues. It sends a message to selected queues.
[Visual Basic] Imports System Imports 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 creates new public and private ' queues. '************************************************** Public Shared Sub Main() ' Create a new instance of the class. Dim myNewQueue As New MyNewQueue() ' Create public and private queues. myNewQueue.CreatePublicQueues() myNewQueue.CreatePrivateQueues() Return End Sub 'Main '************************************************** ' Creates public queues and sends a message. '************************************************** Public Sub CreatePublicQueues() ' Create and connect to a public Message Queuing queue. If Not MessageQueue.Exists(".\newPublicQueue") Then ' Create the queue if it does not exist. Dim myNewPublicQueue As MessageQueue = _ MessageQueue.Create(".\newPublicQueue") ' Send a message to the queue. myNewPublicQueue.Send("My message data.") End If ' Create (but do not connect to) a second public queue. If Not MessageQueue.Exists(".\newPublicResponseQueue") _ Then MessageQueue.Create(".\newPublicResponseQueue") End If Return End Sub 'CreatePublicQueues '************************************************** ' Creates private queues and sends a message. '************************************************** Public Sub CreatePrivateQueues() ' Create and connect to a private Message Queuing queue. If Not MessageQueue.Exists(".\Private$\newPrivateQueue") _ Then ' Create the queue if it does not exist. Dim myNewPrivateQueue As MessageQueue = _ MessageQueue.Create(".\Private$\newPrivateQueue") ' Send a message to the queue. myNewPrivateQueue.Send("My message data.") End If ' Create (but do not connect to) a second private queue. If Not MessageQueue.Exists(".\Private$\newResponseQueue") _ Then MessageQueue.Create(".\Private$\newResponseQueue") End If Return End Sub 'CreatePrivateQueues End Class 'MyNewQueue End Namespace 'MyProject [C#] 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 creates new public and private // queues. //************************************************** public static void Main() { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); // Create public and private queues. myNewQueue.CreatePublicQueues(); myNewQueue.CreatePrivateQueues(); return; } //************************************************** // Creates public queues and sends a message. //************************************************** public void CreatePublicQueues() { // Create and connect to a public Message Queuing queue. if (!MessageQueue.Exists(".\\newPublicQueue")) { // Create the queue if it does not exist. MessageQueue myNewPublicQueue = MessageQueue.Create(".\\newPublicQueue"); // Send a message to the queue. myNewPublicQueue.Send("My message data."); } // Create (but do not connect to) a second public queue. if (!MessageQueue.Exists(".\\newPublicResponseQueue")) { MessageQueue.Create(".\\newPublicResponseQueue"); } return; } //************************************************** // Creates private queues and sends a message. //************************************************** public void CreatePrivateQueues() { // Create and connect to a private Message Queuing queue. if (!MessageQueue.Exists(".\\Private$\\newPrivQueue")) { // Create the queue if it does not exist. MessageQueue myNewPrivateQueue = MessageQueue.Create(".\\Private$\\newPrivQueue"); // Send a message to the queue. myNewPrivateQueue.Send("My message data."); } // Create (but do not connect to) a second private queue. if (!MessageQueue.Exists(".\\Private$\\newResponseQueue")) { MessageQueue.Create(".\\Private$\\newResponseQueue"); } return; } } } [C++] #using <mscorlib.dll> #using <system.dll> #using <system.messaging.dll> using namespace System; using namespace System::Messaging; // This example creates new public and private queues. __gc class MyNewQueue { public: void CreatePublicQueues() { // Create and connect to a public Message Queuing queue. if (!MessageQueue::Exists(S".\\newPublicQueue")) { // Create the queue if it does not exist. MessageQueue* myNewPublicQueue = MessageQueue::Create(S".\\newPublicQueue"); // Send a message to the queue. myNewPublicQueue->Send(S"My message data."); } // Create (but do not connect to) a second public queue. if (!MessageQueue::Exists(S".\\newPublicResponseQueue")) { MessageQueue::Create(S".\\newPublicResponseQueue"); } return; } // Creates private queues and sends a message. public: void CreatePrivateQueues() { // Create and connect to a private Message Queuing queue. if (!MessageQueue::Exists(S".\\Private$\\newPrivQueue")) { // Create the queue if it does not exist. MessageQueue* myNewPrivateQueue = MessageQueue::Create(S".\\Private$\\newPrivQueue"); // Send a message to the queue. myNewPrivateQueue->Send(S"My message data."); } // Create (but do not connect to) a second private queue. if (!MessageQueue::Exists(S".\\Private$\\newResponseQueue")) { MessageQueue::Create(S".\\Private$\\newResponseQueue"); } return; } }; // Provides an entry point into the application. int main() { // Create a new instance of the class. MyNewQueue* myNewQueue = new MyNewQueue(); // Create public and private queues. myNewQueue->CreatePublicQueues(); myNewQueue->CreatePrivateQueues(); return 0; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries From Partially Trusted Code
See Also
MessageQueue Class | MessageQueue Members | System.Messaging Namespace | MessageQueue.Create Overload List | Path | Delete | Exists | MessageQueue
