MessageQueue.Create Method (String, Boolean)
Creates a transactional or non-transactional Message Queuing queue at the specified path.
Assembly: System.Messaging (in System.Messaging.dll)
Parameters
- path
- Type: System.String
The path of the queue to create.
- transactional
- Type: System.Boolean
true to create a transactional queue; false to create a non-transactional queue.
| Exception | Condition |
|---|---|
| ArgumentException | The path parameter is null or is an empty string (""). |
| MessageQueueException | A queue already exists at the specified path. -or- An error occurred when accessing a Message Queuing method. |
You can use this overload to create a transactional queue in Message Queuing. You can create a non-transactional queue, by setting the transactional parameter to false or by calling the other overload of Create(String).
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(String).
The syntax for the path parameter depends on the type of queue it references, as shown in the following table.
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 | Yes |
Local computer and direct format name | Yes |
Remote computer | No |
Remote computer and direct format name | No |
The following code example creates public and private transactional queues. It sends a message to selected queues.
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 transactional queues. //************************************************** public static void Main() { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); // Create transactional queues. myNewQueue.CreatePublicTransactionalQueues(); myNewQueue.CreatePrivateTransactionalQueues(); return; } //************************************************** // Creates public transactional queues and sends a // message. //************************************************** public void CreatePublicTransactionalQueues() { // Create and connect to a public Message Queuing queue. if (!MessageQueue.Exists(".\\newPublicTransQueue1")) { // Create the queue if it does not exist. MessageQueue.Create(".\\newPublicTransQueue1", true); } // Connect to the queue. MessageQueue myNewPublicQueue = new MessageQueue(".\\newPublicTransQueue1"); // Send a message to the queue. // Create a transaction. MessageQueueTransaction myTransaction = new MessageQueueTransaction(); // Begin the transaction. myTransaction.Begin(); // Send the message. myNewPublicQueue.Send("My Message Data.", myTransaction); // Commit the transaction. myTransaction.Commit(); if (!MessageQueue.Exists(".\\newPublicTransQueue2")) { // Create (but do not connect to) second public queue. MessageQueue.Create(".\\newPublicTransQueue2", true); } return; } //************************************************** // Creates private queues and sends a message. //************************************************** public void CreatePrivateTransactionalQueues() { // Create and connect to a private Message Queuing queue. if (!MessageQueue.Exists(".\\Private$\\newPrivTransQ1")) { // Create the queue if it does not exist. MessageQueue.Create(".\\Private$\\newPrivTransQ1", true); } // Connect to the queue. MessageQueue myNewPrivateQueue = new MessageQueue(".\\Private$\\newPrivTransQ1"); // Send a message to the queue. // Create a transaction. MessageQueueTransaction myTransaction = new MessageQueueTransaction(); // Begin the transaction. myTransaction.Begin(); // Send the message. myNewPrivateQueue.Send("My Message Data.", myTransaction); // Commit the transaction. myTransaction.Commit(); // Create (but do not connect to) a second private queue. if (!MessageQueue.Exists(".\\Private$\\newPrivTransQ2")) { MessageQueue.Create(".\\Private$\\newPrivTransQ2", true); } return; } } }
- 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.
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.