Export (0) Print
Expand All

MessageQueue.Create Method (String, Boolean)

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Shared Function Create( _
   ByVal path As String, _
   ByVal transactional As Boolean _
) As MessageQueue
[C#]
public static MessageQueue Create(
 string path,
 bool transactional
);
[C++]
public: static MessageQueue* Create(
 String* path,
 bool transactional
);
[JScript]
public static function Create(
   path : String,
 transactional : Boolean
) : MessageQueue;

Parameters

path
The path of the queue to create.
transactional
true to create a transactional queue; false to create a nontransactional queue.

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

You can use this overload to create a transactional queue in Message Queuing. You can create a nontransactional queue, by setting the transactional parameter to false or by calling the other overload of Create.

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 transactional 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 transactional queues.
        '**************************************************

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

            ' Create transactional queues.
            myNewQueue.CreatePublicTransactionalQueues()
            myNewQueue.CreatePrivateTransactionalQueues()

            Return

        End Sub 'Main


        '**************************************************
        ' Creates public transactional queues and sends a 
        ' message.
        '**************************************************

        Public Sub CreatePublicTransactionalQueues()

            ' Create and connect to a public Message Queuing queue.
            If Not MessageQueue.Exists(".\newPublicTransQueue1") Then

                ' Create the queue if it does not exist.
                Dim myNewPublicQueue As MessageQueue = _
                    MessageQueue.Create(".\newPublicTransQueue1", _
                    True)

                ' Send a message to the queue.
                myNewPublicQueue.Send("My message data.", _
                    New MessageQueueTransaction())
            End If

            If Not MessageQueue.Exists(".\newPublicTransQueue2") Then

                ' Create (but do not connect to) a second queue.
                MessageQueue.Create(".\newPublicTransQueue2", True)
            End If

            Return

        End Sub 'CreatePublicTransactionalQueues


        '**************************************************
        ' Creates private queues and sends a message.
        '**************************************************

        Public Sub CreatePrivateTransactionalQueues()

            ' Create and connect to a private Message Queuing queue.
            If Not MessageQueue.Exists(".\Private$\newPrivTransQ1") _
                Then

                ' Create the queue if it does not exist.
                Dim myNewPrivateQueue As MessageQueue = _
                    MessageQueue.Create(".\Private$\newPriTransQ1", _
                    True)

                ' Send a message to the queue.
                myNewPrivateQueue.Send("My message data.", New _
                    MessageQueueTransaction())
            End If

            ' Create (but do not connect to) a second private queue.
            If Not MessageQueue.Exists(".\Private$\newPrivTransQ2") _
                Then

                MessageQueue.Create(".\Private$\newPrivTransQ2", True)
            End If

            Return

        End Sub 'CreatePrivateTransactionalQueues

    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 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 myNewPublicQueue = 
                    MessageQueue.Create(".\\newPublicTransQueue1", 
                    true);

                // Send a message to the queue.
                myNewPublicQueue.Send("My message data.", new 
                    MessageQueueTransaction());
            }

            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 myNewPrivateQueue = 
                    MessageQueue.Create(".\\Private$\\newPrivTransQ1", 
                    true);

                // Send a message to the queue.
                myNewPrivateQueue.Send("My message data.", new 
                    MessageQueueTransaction());
            }

            // Create (but do not connect to) a second private queue.
            if (!MessageQueue.Exists(".\\Private$\\newPrivTransQ2"))
            {
                MessageQueue.Create(".\\Private$\\newPrivTransQ2", 
                    true);
            }

            return;
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;

__gc class MyNewQueue 
{
public:
    // Creates public transactional queues and sends a 
    // message.
    void CreatePublicTransactionalQueues() 
    {
        // Create and connect to a public message Queuing queue.
        if (!MessageQueue::Exists(S".\\newPublicTransQueue1")) 
        {
            // Create the queue if it does not exist.
            MessageQueue* myNewPublicQueue = 
                MessageQueue::Create(S".\\newPublicTransQueue1", true);

            // Send a message to the queue.
            myNewPublicQueue->Send(S"My message data.", new 
                MessageQueueTransaction());
        }

        if (!MessageQueue::Exists(S".\\newPublicTransQueue2")) 
        {
            // Create (but do not connect to) second public queue
            MessageQueue::Create(S".\\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(S".\\Private$\\newPrivTransQ1")) 
        {
            // Create the queue if it does not exist.
            MessageQueue* myNewPrivateQueue = 
                MessageQueue::Create(S".\\Private$\\newPrivTransQ1", true);

            // Send a message to the queue.
            myNewPrivateQueue->Send(S"My message data.", new MessageQueueTransaction());
        }

        // Create (but do not connect to) a second private queue.
        if (!MessageQueue::Exists(S".\\Private$\\newPrivTransQ2")) 
        {
            MessageQueue::Create(S".\\Private$\\newPrivTransQ2", 
                true);
        }

        return;
    }
};

// Provides an entry point into the application.
// This example creates new transactional queues.
int main() 
{
    // Create a new instance of the class.
    MyNewQueue* myNewQueue = new MyNewQueue();

    // Create transactional queues.
    myNewQueue->CreatePublicTransactionalQueues();
    myNewQueue->CreatePrivateTransactionalQueues();

    return 0;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter 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: 

See Also

MessageQueue Class | MessageQueue Members | System.Messaging Namespace | MessageQueue.Create Overload List | Path | Delete | Exists | MessageQueue | Transactional

Show:
© 2014 Microsoft