次の方法で共有


MessageQueue コンストラクタ (String, Boolean)

指定した読み取りアクセス制限を持つ指定したパスのメッセージ キューのキューを参照する MessageQueue クラスの新しいインスタンスを初期化します。

名前空間: System.Messaging
アセンブリ: System.Messaging (system.messaging.dll 内)

構文

'宣言
Public Sub New ( _
    path As String, _
    sharedModeDenyReceive As Boolean _
)
'使用
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
)

パラメータ

  • path
    この MessageQueue が参照するキューの場所。ローカル コンピュータの場合は "." にできます。このパラメータの正しい構文の詳細については、「解説」を参照してください。
  • sharedModeDenyReceive
    キューにアクセスする最初のアプリケーションに排他読み取りアクセス許可を与える場合は true。それ以外の場合は false

例外

例外の種類 条件

ArgumentException

Path プロパティが無効です。設定されていない可能性があります。

解説

パス、書式名、ラベルが判明している、メッセージ キューの特定のキューに新しい MessageQueue を結び付ける場合は、このオーバーロードを使用します。キューを参照する最初のアプリケーションに排他アクセス許可を与える場合は、sharedModeDenyReceive パラメータに true を設定します。それ以外の場合は、sharedModeDenyReceive に false を設定するか、path パラメータだけを指定するコンストラクタを使用します。

sharedModeDenyReceive に true を設定すると、他のアプリケーションも含めて、そのメッセージ キューのキューにアクセスするすべてのオブジェクトが影響を受けます。パラメータの影響は、このアプリケーションだけにとどまりません。

MessageQueue コンストラクタは MessageQueue クラスの新しいインスタンスを作成します。メッセージ キューの新しいキューは作成しません。メッセージ キューに新しいキューを作成するには、Create(String) を使用します。

path パラメータの構文は、キューの種類によって異なります。

キューの種類

構文

パブリック キュー

MachineName\QueueName

プライベート キュー

MachineName\Private$\QueueName

ジャーナル キュー

MachineName\QueueName\Journal$

コンピュータの履歴キュー

MachineName\Journal$

コンピュータ配信不能キュー

MachineName\Deadletter$

コンピュータ トランザクション配信不能キュー

MachineName\XactDeadletter$

メッセージ キューのキューの書式名またはラベルを使用してキューのパスを記述することもできます。

参照

構文

書式名

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

ラベル

Label: [ label ]

Label: TheLabel

オフラインで作業をするには、表示名の構文ではなく書式名構文を使用する必要があります。表示名の構文を使用すると、パスを書式名に解決するプライマリ ドメイン コントローラ (Active Directory が常駐) が利用できないため、例外がスローされます

MessageQueue が sharedModeDenyReceive パラメータに true を設定してキューを開くと、そのキューから読み取ろうとするあらゆる MessageQueue は、共有違反のため MessageQueueException を生成します。既に MessageQueue が非排他モードでキューにアクセスしているときに、別の MessageQueue が排他モードでそのキューにアクセスしようとした場合にも、MessageQueueException がスローされます。

MessageQueue のインスタンスの初期プロパティ値を次の表に示します。これらの値は、path パラメータで指定されたパスのメッセージ キューのキュー プロパティに基づきます。

プロパティ

初期値

Authenticate

false

BasePriority

0

Category

Empty

DefaultPropertiesToSend

DefaultPropertiesToSend クラスの既定のコンストラクタで設定される値。

EncryptionRequired

メッセージ キューのキューのプライバシ レベル設定が "Body" の場合は true。それ以外の場合は false

Formatter

XmlMessageFormatter

Label

Empty

MachineName

メッセージ キューのキューのコンピュータ名プロパティの値。

MaximumJournalSize

InfiniteQueueSize

MaximumQueueSize

InfiniteQueueSize

MessageReadPropertyFilter

MessagePropertyFilter クラスの既定のコンストラクタで設定される値。

Path

コンストラクタで設定しない場合は Empty

QueueName

コンストラクタで設定しない場合は Empty

DenySharedReceive

sharedModeDenyReceive パラメータの値。

UseJournalQueue

メッセージ キューオブジェクトの履歴設定が有効な場合は true。それ以外の場合は false

使用例

新しい MessageQueue を排他アクセスで作成し、パスを設定し、メッセージをキューに送信するコード例を次に示します。

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 のセキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「」を参照してください。

プラットフォーム

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

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 2.0

参照

関連項目

MessageQueue クラス
MessageQueue メンバ
System.Messaging 名前空間
FormatName
Label
Path
QueueName
DenySharedReceive