Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 1.1
.NET Framework
Reference
Class Library
System.Messaging
MessageQueue Class
Methods
Create Method
This page is specific to
Microsoft Visual Studio 2003/.NET Framework 1.1

Other versions are also available for the following:
.NET Framework Class Library
MessageQueue.Create Method

Creates a new queue at the specified path on a Message Queuing server.

Overload List

Creates a nontransactional Message Queuing queue at the specified path.

[Visual Basic] Overloads Public Shared Function Create(String) As MessageQueue
[C#] public static MessageQueue Create(string);
[C++] public: static MessageQueue* Create(String*);
[JScript] public static function Create(String) : MessageQueue;

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

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

Example

[Visual Basic, C#, C++] The following example creates public and private transactional queues. It sends a message to selected queues.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Create. For other examples that might be available, see the individual overload topics.
[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.

See Also

MessageQueue Class | MessageQueue Members | System.Messaging Namespace

© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker