}
protected void Button2_Click(object sender, EventArgs e)
{
MessageQueue msq;
Message msg = new Message();
BinaryReader br;
&nb
sp; string msgs;
if (MessageQueue.Exists(@".\private$\tests"))
{
msq = new MessageQueue(@".\private$\tests");
//說明網上很多版本寫作msq = new MessageQueue(".\\private$\tests"),運行時將出現錯誤。
}
else
{
msq = MessageQueue.Create(@".\private$\tests");
}
try
{
msg = msq.Receive(new TimeSpan(0, 0, 3));
br = new BinaryReader(msg.BodyStream);
msgs = new string(br.ReadChars(Convert.ToInt32(msg.BodyStream.Length)));
}
catch
{
msgs = "沒有消息!";
}
Label1.Text = msgs;
}