MessageQueue.Close メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > MessageQueue.Close メソッドの意味・解説 

MessageQueue.Close メソッド

MessageQueue割り当てられすべてのリソース解放します。

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

解説解説

Close は、MessageQueue関連付けられたすべてのリソース解放します。共有リソースがあれば、共有リソース解放されます。たとえば、次の C# コードで示すように Send(Object) メソッド呼び出したときに、まだリソース利用できる場合は、システムがこれらのリソース自動的に取得します

 myMessageQueue.Send("Text 1.");
 myMessageQueue.Close();
 myMessageQueue.Send("Text 2."); //Resources are re-acquired.

Close呼び出すと、メッセージ キューキュー直接アクセスするすべての MessageQueue プロパティ消去されます。Path、DefaultPropertiesToSend、Formatter、および MessageReadPropertyFilter は、すべてそのまま残ります

Close は、常にキュー対す読み取りハンドルおよび書き込みハンドル解放するとは限りません。これらのハンドルは、共有されている場合があるためです。次の手順いずれか実行すると、Close で、キュー対す読み取りハンドルおよび書き込みハンドル確実に解放できます

メッセージ キュー サーバーキュー削除する前にキューに対して Close呼び出す必要があります呼び出さないと、メッセージキュー送信されたときに例外スローされたり、配信不能キュー到達することがあります

このメソッド各種ワークグループ モード使用できるかどうか次の表に示します

使用例使用例

メッセージ キューキュー閉じコード例次に示します

Imports System
Imports System.Messaging

  
'Provides a container class for the example.

Public Class MyNewQueue



        ' Provides an entry point into the application.
        '     
        ' This example closes a queue and frees its 
        ' resources.
 

        Public Shared Sub
 Main()

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

            ' Send a message to a queue.
            myNewQueue.SendMessage()

            ' Receive a message from a queue.
            myNewQueue.ReceiveMessage()

            Return

        End Sub 'Main



        ' Sends a message to a queue.
 

        Public Sub SendMessage()

            ' Connect to a queue on the local computer.
            Dim myQueue As New
 MessageQueue(".\myQueue")

            ' Send a message to the queue.
            myQueue.Send("My message data1.")

            ' Explicitly release resources.
            myQueue.Close()

            ' Attempt to reacquire resources.
            myQueue.Send("My message data2.")

            Return

        End Sub 'SendMessage



        ' Receives a message from a queue.


        Public Sub ReceiveMessage()

            ' Connect to the a on the local computer.
            Dim myQueue As New
 MessageQueue(".\myQueue")

            ' Set the formatter to indicate the body contains an 
            ' Order.
            myQueue.Formatter = New XmlMessageFormatter(New
 Type() _
                {GetType([String])})

            Try
                ' Receive and format the message. 
                Dim myMessage1 As Message =
 myQueue.Receive()
                Dim myMessage2 As Message =
 myQueue.Receive()

            Catch
                ' Handle sources of any MessageQueueException.

                ' Catch other exceptions as necessary.

            Finally

                ' Free resources.
                myQueue.Close()

            End Try

            Return

        End Sub 'ReceiveMessage

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 closes a queue and frees its 
        // resources.
        //**************************************************

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

            // Send a message to a queue.
            myNewQueue.SendMessage();

            // Receive a message from a queue.
            myNewQueue.ReceiveMessage();

            return;
        }


        //**************************************************
        // Sends a message to a queue.
        //**************************************************
        
        public void SendMessage()
        {
            // Connect to a queue on the local computer.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");

            // Send a message to the queue.
            myQueue.Send("My message data1.");
            
            // Explicitly release resources.
            myQueue.Close();

            // Attempt to reacquire resources.
            myQueue.Send("My message data2.");

            return;
        }


        //**************************************************
        // Receives a message from a queue.
        //**************************************************
        
        public  void ReceiveMessage()
        {
            // Connect to the a on the local computer.
            MessageQueue myQueue = new MessageQueue(".\\myQueue");

            // Set the formatter to indicate body contains an Order.
            myQueue.Formatter = new XmlMessageFormatter(new
 Type[]
                {typeof(String)});
            
            try
            {
                // Receive and format the message. 
                Message myMessage1 = myQueue.Receive();
                Message myMessage2 = myQueue.Receive();
            }
            
            catch (MessageQueueException)
            {
                // Handle sources of any MessageQueueException.
            }

            // Catch other exceptions as necessary.

            finally
            {
                // Free resources.
                myQueue.Close();
            }

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

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

   // Sends a message to a queue.
   void SendMessage()
   {
      // Connect to a queue on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

      // Send a message to the queue.
      myQueue->Send( "My message data1." );

      // Explicitly release resources.
      myQueue->Close();

      // Attempt to reaquire resources.
      myQueue->Send( "My message data2." );
      return;
   }

   // Receives a message from a queue.
   void ReceiveMessage()
   {
      // Connect to the a on the local computer.
      MessageQueue^ myQueue = gcnew MessageQueue( ".\\myQueue" );

      // Set the formatter to indicate body contains an Order.
      array<Type^>^p = gcnew array<Type^>(1);
      p[ 0 ] = String::typeid;
      myQueue->Formatter = gcnew XmlMessageFormatter( p );
      try
      {
         // Receive and format the message. 
         Message^ myMessage1 = myQueue->Receive();
         Message^ myMessage2 = myQueue->Receive();
      }
      catch ( MessageQueueException^ ) 
      {
         // Handle sources of any MessageQueueException.
      }
      finally
      {
         // Free resources.
         myQueue->Close();
      }

      return;
   }
};


// Provides an entry point into the application.
// This example closes a queue and frees its 
// resources.
int main()
{
   // Create a new instance of the class.
   MyNewQueue^ myNewQueue = gcnew MyNewQueue;

   // Send a message to a queue.
   myNewQueue->SendMessage();

   // Receive a message from a queue.
   myNewQueue->ReceiveMessage();
   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 closes a queue and frees its 
    // resources.
    //**************************************************
    public static void main(String[]
 args)
    {
        // Create a new instance of the class.
        MyNewQueue myNewQueue = new MyNewQueue();
        // Send a message to a queue.
        myNewQueue.SendMessage();
        // Receive a message from a queue.
        myNewQueue.ReceiveMessage();
        return;
    } //main

    //**************************************************
    // Sends a message to a queue.
    //**************************************************
    public void SendMessage()
    {
        // Connect to a queue on the local computer.
        MessageQueue myQueue = new MessageQueue(".\\myQueue");
        // Send a message to the queue.
        myQueue.Send("My message data1.");
        // Explicitly release resources.
        myQueue.Close();
        // Attempt to reaquire resources.
        myQueue.Send("My message data2.");
        return;
    } //SendMessage

    //**************************************************
    // Receives a message from a queue.
    //**************************************************
    public void ReceiveMessage()
    {
        // Connect to the a on the local computer.
        MessageQueue myQueue = new MessageQueue(".\\myQueue");
        // Set the formatter to indicate body contains an Order.
        myQueue.set_Formatter(new XmlMessageFormatter(new
 Type[]
            { String.class.ToType() }));

        try {
            // Receive and format the message. 
            Message myMessage1 = myQueue.Receive();
            Message myMessage2 = myQueue.Receive();
        }
        catch (MessageQueueException exp) {
            // Handle sources of any MessageQueueException.
        }
        // Catch other exceptions as necessary.
        finally {
            // Free resources.
            myQueue.Close();
        }
        return;
    } //ReceiveMessage
} //MyNewQueue
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からMessageQueue.Close メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からMessageQueue.Close メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からMessageQueue.Close メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

MessageQueue.Close メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MessageQueue.Close メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS