MessageQueue.Close メソッド
アセンブリ: System.Messaging (system.messaging.dll 内)

Dim instance As MessageQueue instance.Close

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 で、キューに対する読み取りハンドルおよび書き込みハンドルを確実に解放できます。
-
排他アクセスで MessageQueue を作成する。これを行うには、MessageQueue(String,Boolean) コンストラクタまたは MessageQueue(String,Boolean,Boolean) コンストラクタを呼び出し、sharedModeDenyReceive パラメータを true に設定します。
-
接続キャッシュを無効にして MessageQueue を作成する。これを行うには、MessageQueue(String,Boolean,Boolean) コンストラクタを呼び出し、enableConnectionCache パラメータを false に設定します。
-
接続キャッシュを無効にする。これを行うには、EnableConnectionCache プロパティを false に設定します。
メッセージ キュー サーバーのキューを削除する前に、キューに対して 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


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からMessageQueue.Close メソッドを検索する場合は、下記のリンクをクリックしてください。

- MessageQueue.Close メソッドのページへのリンク