Creates a non-transactional Message Queuing queue at the specified path.
Namespace: System.Messaging
Assembly: System.Messaging (in system.messaging.dll)
Visual Basic (Declaration)
Public Shared Function Create ( _
path As String _
) As MessageQueue
Dim path As String
Dim returnValue As MessageQueue
returnValue = MessageQueue.Create(path)
public static MessageQueue Create (
string path
)
public:
static MessageQueue^ Create (
String^ path
)
public static MessageQueue Create (
String path
)
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.
| 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 method. |
Use this overload to create a non-transactional 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(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 queues. It sends a message to selected queues.
Imports System
Imports System.Messaging
' Provides a container class for the example.
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
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;
}
}
}
#using <system.dll>
#using <system.messaging.dll>
using namespace System;
using namespace System::Messaging;
// This example creates new public and private queues.
ref class MyNewQueue
{
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.
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;
}
};
// Provides an entry point into the application.
int main()
{
// Create a new instance of the class.
MyNewQueue^ myNewQueue = gcnew MyNewQueue;
// Create public and private queues.
myNewQueue->CreatePublicQueues();
myNewQueue->CreatePrivateQueues();
return 0;
}
package MyProject;
import System.*;
import System.Messaging.*;
/// <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(String[] args)
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Create public and private queues.
myNewQueue.CreatePublicQueues();
myNewQueue.CreatePrivateQueues();
return;
} //main
/***************************************************/
// 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;
} //CreatePublicQueues
/***************************************************/
// 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;
} //CreatePrivateQueues
} //MyNewQueue
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
.NET Framework
Supported in: 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 2.0