Freigeben über


MessageQueue-Konstruktor (String, Boolean)

Initialisiert eine neue Instanz der MessageQueue-Klasse mit der angegebenen Lesezugriffsbeschränkung, die auf die Message Queuing-Warteschlange unter dem angegebenen Pfad verweist.

Namespace: System.Messaging
Assembly: System.Messaging (in system.messaging.dll)

Syntax

'Declaration
Public Sub New ( _
    path As String, _
    sharedModeDenyReceive As Boolean _
)
'Usage
Dim path As String
Dim sharedModeDenyReceive As Boolean

Dim instance As New MessageQueue(path, sharedModeDenyReceive)
public MessageQueue (
    string path,
    bool sharedModeDenyReceive
)
public:
MessageQueue (
    String^ path, 
    bool sharedModeDenyReceive
)
public MessageQueue (
    String path, 
    boolean sharedModeDenyReceive
)
public function MessageQueue (
    path : String, 
    sharedModeDenyReceive : boolean
)

Parameter

  • path
    Der Speicherort der Warteschlange, auf die diese MessageQueue verweist. Dieser kann für den lokalen Computer "." lauten. Weitere Informationen über die korrekte Syntax für diesen Parameter finden Sie im Abschnitt Hinweise.
  • sharedModeDenyReceive
    true, wenn der ersten Anwendung, die auf die Warteschlange zugreift, exklusiver Zugriff gewährt werden soll, andernfalls false.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentException

Die Path-Eigenschaft ist ungültig. Möglicherweise wurde sie nicht festgelegt.

Hinweise

Verwenden Sie diese Überladung, wenn Sie die neue MessageQueue mit einer bestimmten Message Queuing-Warteschlange verbinden möchten, deren Pfad, Formatname oder Bezeichnung Ihnen bekannt ist. Wenn Sie der ersten Anwendung, die auf die Warteschlange zugreift, exklusiven Zugriff gewähren möchten, müssen Sie den sharedModeDenyReceive-Parameter auf true festlegen. Legen Sie andernfalls sharedModeDenyReceive auf false fest, oder verwenden Sie den Konstruktor, der nur über einen path-Parameter verfügt.

Wenn sharedModeDenyReceive auf true festgelegt wird, sind davon alle Objekte betroffen, die auf die Message Queuing-Warteschlange zugreifen, auch andere Anwendungen. Die Auswirkungen des Parameters sind nicht auf diese Anwendung beschränkt.

Der MessageQueue-Konstruktor erstellt eine neue Instanz der MessageQueue-Klasse, erstellt jedoch keine neue Message Queuing-Warteschlange. Eine neue Message Queuing-Warteschlange erstellen Sie mithilfe von Create(String).

Die Syntax für den path-Parameter hängt vom Typ der Warteschlange ab.

Warteschlangentyp

Syntax

Öffentliche Warteschlange

MachineName\QueueName

Private Warteschlange

MachineName\Private$\QueueName

Journalwarteschlange

MachineName\QueueName\Journal$

Journalwarteschlange des Computers

MachineName\Journal$

Dead Letter-Warteschlange des Computers

MachineName\Deadletter$

Transaktionale Dead Letter-Warteschlange des Computers

MachineName\XactDeadletter$

Alternativ können Sie den Formatnamen oder die Bezeichnung zur Angabe des Pfades für die Warteschlange verwenden.

Verweis

Syntax

Beispiel

Formatname

FormatName: [ format name ]

FormatName:Public= 5A5F7535-AE9A-41d4-935C-845C2AFF7112

FormatName:DIRECT=SPX: NetworkNumber; HostNumber\QueueName

FormatName:DIRECT=TCP: IPAddress\QueueName

FormatName:DIRECT=OS: MachineName\QueueName

Bezeichnung

Label: [ label ]

Label: TheLabel

Um offline arbeiten zu können, müssen Sie die Syntax für den Formatnamen anstelle der Syntax für den angezeigten Namen verwenden. Andernfalls wird eine Ausnahme ausgelöst, da der primäre Domänencontroller (auf dem sich Active Directory befindet) nicht zur Auflösung des Pfades in den Formatnamen zur Verfügung steht.

Wenn eine MessageQueue eine Warteschlange öffnet und dabei der sharedModeDenyReceive-Parameter auf true festgelegt ist, löst jede MessageQueue, die danach versucht, aus dieser Warteschlange zu lesen, aufgrund einer Zugriffsverletzung eine MessageQueueException aus. Es wird auch dann eine MessageQueueException ausgelöst, wenn eine MessageQueue exklusiv auf eine Warteschlange zuzugreifen versucht, während eine andere MessageQueue bereits nicht exklusiv auf die Warteschlange zugreift.

In der folgenden Tabelle werden die anfänglichen Eigenschaftenwerte für eine Instanz von MessageQueue aufgeführt. Diese Werte basieren auf den Eigenschaften der Message Queuing-Warteschlange unter dem Pfad, der im path-Parameter angegeben wurde.

Eigenschaft

Anfangswert

Authenticate

false.

BasePriority

0.

Category

Empty.

DefaultPropertiesToSend

Die vom Standardkonstruktor der DefaultPropertiesToSend-Klasse festgelegten Werte.

EncryptionRequired

true, wenn die Sicherheitsebeneneinstellung der Message Queuing-Warteschlange "Body" lautet, andernfalls false.

Formatter

XmlMessageFormatter.

Label

Empty.

MachineName

Der Wert der Eigenschaft für den Computernamen der Message Queuing-Warteschlange.

MaximumJournalSize

InfiniteQueueSize.

MaximumQueueSize

InfiniteQueueSize.

MessageReadPropertyFilter

Die vom Standardkonstruktor der MessagePropertyFilter-Klasse festgelegten Werte.

Path

Empty, sofern nicht vom Konstruktor festgelegt.

QueueName

Empty, sofern nicht vom Konstruktor festgelegt.

DenySharedReceive

Der Wert des sharedModeDenyReceive-Parameters.

UseJournalQueue

true, wenn die Journaleinstellung des Message Queuing-Objekts aktiviert ist, andernfalls false.

Beispiel

Im folgenden Codebeispiel wird eine neue MessageQueue mit exklusivem Zugriff erstellt, ihr Pfad festgelegt und eine Meldung an die Warteschlange gesendet.

Imports System
Imports System.Messaging

Public Class MyNewQueue


        ' Provides an entry point into the application.
        '        
        ' This example connects to a message queue, and
        ' requests exclusive read access to the queue.
 

        Public Shared Sub Main()

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

            ' Output the count of Lowest priority messages.
            myNewQueue.GetExclusiveAccess()

            Return

        End Sub 'Main


  
        ' Requests exlusive read access to the queue. If
        ' access is granted, receives a message from the 
        ' queue.
  

        Public Sub GetExclusiveAccess()

            Try

                ' Request exclusive read access to the queue.
                Dim myQueue As New MessageQueue(".\myQueue", True)

                ' Receive a message. This is where a SharingViolation 
                ' exception would be thrown.
                Dim myMessage As Message = myQueue.Receive()

            Catch e As MessageQueueException

                ' Handle request for denial of exclusive read access.
                If e.MessageQueueErrorCode = _
                    MessageQueueErrorCode.SharingViolation Then

                    Console.WriteLine("Denied exclusive read access.")

                End If

                ' Handle other sources of a MessageQueueException.

                ' Handle other exceptions as necessary.

            End Try

            Return

        End Sub 'GetExclusiveAccess

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 connects to a message queue, and
        // requests exclusive read access to the queue.
        //**************************************************

        public static void Main()
        {
            // Create a new instance of the class.
            MyNewQueue myNewQueue = new MyNewQueue();

            // Output the count of Lowest priority messages.
            myNewQueue.GetExclusiveAccess();
                        
            return;
        }


        //**************************************************
        // Requests exlusive read access to the queue. If
        // access is granted, receives a message from the 
        // queue.
        //**************************************************
        
        public void GetExclusiveAccess()
        {
            try
            {
                // Request exclusive read access to the queue.
                MessageQueue myQueue = new 
                    MessageQueue(".\\myQueue", true);

                // Receive a message. This is where SharingViolation 
                // exceptions would be thrown.
                Message myMessage = myQueue.Receive();
            }
            
            catch (MessageQueueException e)
            {
                // Handle request for denial of exclusive read access.
                if (e.MessageQueueErrorCode == 
                    MessageQueueErrorCode.SharingViolation)
                {
                    Console.WriteLine("Denied exclusive read access");
                }

                // Handle other sources of a MessageQueueException.
            }

            // Handle other exceptions as necessary.

            return;
        }
    }
}
#using <system.dll>
#using <system.messaging.dll>

using namespace System;
using namespace System::Messaging;
ref class MyNewQueue
{
public:

   // Requests exlusive read access to the queue. If
   // access is granted, receives a message from the 
   // queue.
   void GetExclusiveAccess()
   {
      try
      {
         
         // Request exclusive read access to the queue.
         MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue",true );
         
         // Receive a message. This is where SharingViolation 
         // exceptions would be thrown.
         Message^ myMessage = myQueue->Receive();
      }
      catch ( MessageQueueException^ e ) 
      {
         
         // Handle request for denial of exclusive read access.
         if ( e->MessageQueueErrorCode == MessageQueueErrorCode::SharingViolation )
         {
            Console::WriteLine( "Denied exclusive read access" );
         }

         
         // Handle other sources of a MessageQueueException.
      }

      
      // Handle other exceptions as necessary.
      return;
   }

};


// Provides an entry point into the application.
// This example connects to a message queue, and
// requests exclusive read access to the queue.
int main()
{
   
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;
   
   // Output the count of Lowest priority messages.
   myNewQueue->GetExclusiveAccess();
   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 connects to a message queue, and
    // requests exclusive read access to the queue.
    //**************************************************
    public static void main(String[] args)
    {
        // Create a new instance of the class.
        MyNewQueue myNewQueue = new MyNewQueue();
        // Output the count of Lowest priority messages.
        myNewQueue.GetExclusiveAccess();
        return;
    } //main

    //**************************************************
    // Requests exlusive read access to the queue. If
    // access is granted, receives a message from the 
    // queue.
    //**************************************************
    public void GetExclusiveAccess()
    {
        try {
            // Request exclusive read access to the queue.
            MessageQueue myQueue = new MessageQueue(".\\myQueue", true);
            // Receive a message.This is where SharingViolation 
            // exceptions would be thrown.
            Message myMessage = myQueue.Receive();
        }
        catch (MessageQueueException e) {
            // Handle request for denial of exclusive read access.
            if (e.get_MessageQueueErrorCode().
                Equals(MessageQueueErrorCode.SharingViolation)) {
                Console.WriteLine("Denied exclusive read access");
            }
            // Handle other sources of a MessageQueueException.
        }        
        // Handle other exceptions as necessary.
        return;
    } //GetExclusiveAccess
} //MyNewQueue

.NET Framework-Sicherheit

  • Volle Vertrauenswürdigkeit für den unmittelbaren Aufrufer. Dieser Member kann von nur teilweise vertrauenswürdigem Code nicht verwendet werden. Weitere Informationen finden Sie unter .

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

MessageQueue-Klasse
MessageQueue-Member
System.Messaging-Namespace
FormatName
Label
Path
QueueName
DenySharedReceive