MessageBuffer.Close Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Finishes working with the buffer.
public:
abstract void Close();
public abstract void Close ();
abstract member Close : unit -> unit
Public MustOverride Sub Close ()
Examples
The following example demonstrates how to properly close a message buffer.
public void AfterReceiveReply(ref Message reply, object correlationState)
{
// Create the buffer.
MessageBuffer buffer = reply.CreateBufferedCopy(13000);
// Inspect the response (for example, extract the body contents).
Message thisReply = buffer.CreateMessage();
XmlDictionaryReader reader = thisReply.GetReaderAtBodyContents();
var info = new StringBuilder();
XmlWriter writer = XmlWriter.Create(info);
writer.WriteNode(reader, true);
writer.Close();
// Resolution: Re-create the message from the buffer before
// closing.
reply = buffer.CreateMessage();
// You can close the buffer after the message has been recreated.
buffer.Close();
}
Remarks
You should always close a MessageBuffer instance by calling Close when finished working with it. This allows system resources to potentially be freed sooner.
If you have called CreateBufferedCopy to create a message buffer of a message, and inspected the message using CreateMessage, you will get a InvalidOperationException when you attempt to close the buffer using this method. To avoid this problem, you need to recreate the message from the buffer before closing. See the code sample in the Example section for a demonstration of the previous scenario and a way to resolve this problem.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기