<?xml version="1.0" encoding="UTF-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>以程式設計的方式傳送和接收訊息</Title>
      <Author>Microsoft Corporation</Author>
      <Description>傳送訊息至本機電腦上的佇列、接收該訊息，以及將主體格式化為字串。</Description>
      <Shortcut>mqSendRec</Shortcut>
    </Header>
    <Snippet>
      <References>
        <Reference>
          <Assembly>System.Messaging.dll</Assembly>
          <Url/>
        </Reference>
      </References>
      <Imports>
        <Import>
          <Namespace>System</Namespace>
        </Import>
        <Import>
          <Namespace>Microsoft.VisualBasic</Namespace>
        </Import>
        <Import>
          <Namespace>System.Messaging</Namespace>
        </Import>
      </Imports>
      <Declarations>
        <Literal>
          <ID>QueueName</ID>
          <Type>String</Type>
          <ToolTip>取代為佇列名稱。"." 代表本機電腦。</ToolTip>
          <Default>".\QueueName"</Default>
        </Literal>
        <Literal>
          <ID>Message</ID>
          <Type>String</Type>
          <ToolTip>取代為訊息。訊息可以是任何物件類型。</ToolTip>
          <Default>"Message text"</Default>
        </Literal>
        <Literal>
          <ID>BodyType</ID>
          <Type>System.Type</Type>
          <ToolTip>取代為訊息的類型。這個類型必須符合 Send 命令中傳送的物件類型。</ToolTip>
          <Default>GetType(String)</Default>
        </Literal>
      </Declarations>
      <Code Language="VB" Kind="method body"><![CDATA[Dim queue As New System.Messaging.MessageQueue($QueueName$)

' Send a message to the queue.
queue.Send($Message$)

' Wait for the message to arrive, and then remove
' it from the queue.
Dim msg As Message
msg = queue.Receive(New TimeSpan(0, 0, 3))

' Convert the body to a string.
msg.Formatter = New XmlMessageFormatter(New Type() {$BodyType$})
Dim text As String = msg.Body.ToString]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
