MessageQueue.Close 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
에서 할당한 모든 리소스를 해제합니다 MessageQueue.
public:
void Close();
public void Close();
member this.Close : unit -> unit
Public Sub Close ()
예제
다음 코드 예제에서는 메시지 큐를 닫습니다.
#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;
}
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;
}
}
}
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
' 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
' 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
End Class
설명
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, Boolean) 생성자를 호출 MessageQueue(String, Boolean) 하고 매개 변수
true를sharedModeDenyReceive.로 설정합니다.연결 캐싱을 MessageQueue 사용하지 않도록 설정하여 만듭니다. 이렇게 하려면 생성자를 호출 MessageQueue(String, Boolean, Boolean) 하고 매개 변수
false를enableConnectionCache.로 설정합니다.연결 캐싱을 사용하지 않도록 설정합니다. 이렇게 하려면 속성을
false.로 설정합니다EnableConnectionCache.
메시지 큐 서버에서 큐를 삭제하기 전에 큐를 호출 Close 해야 합니다. 그렇지 않으면 큐로 전송된 메시지가 예외를 throw하거나 배달 못 한 편지 큐에 나타날 수 있습니다.
다음 표에서는 이 메서드를 다양한 작업 그룹 모드에서 사용할 수 있는지 여부를 보여 줍니다.
| 작업 그룹 모드 | 사용 가능 |
|---|---|
| 로컬 컴퓨터 | 예 |
| 로컬 컴퓨터 및 직접 형식 이름 | 예 |
| 원격 컴퓨터 | 예 |
| 원격 컴퓨터 및 직접 형식 이름 | 예 |