110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using MSMQ;
namespace MyTest
{
public class Form2 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
MSMQ.MSMQQueueInfoClass mqinfor=new MSMQQueueInfoClass();
private void Form2_Load(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
mqinfor.FormatName="Direct=TCP:" + this.txthost.Text + "\\" + this.txtpath.Text;
MSMQ.MSMQQueue mq=mqinfor.Open(MSMQ.MQACCESS.MQ_SEND_ACCESS.GetHashCode(),MSMQ.MQSHARE.MQ_DENY_NONE.GetHashCode());
MSMQ.MSMQMessageClass msg=new MSMQMessageClass();
msg.Label="activeX Test";
msg.Body=this.txtmsg.Text;
MSMQ.MSMQTransactionClass MQ_NO_TRANSACTION=new MSMQTransactionClass();
object a=MQ_NO_TRANSACTION;
msg.Send(mq,ref a);
}
private void button2_Click(object sender, System.EventArgs e)
{
try
{
mqinfor.FormatName="Direct=TCP:" + this.txthost.Text + "\\" + this.txtpath.Text;
MSMQ.MSMQQueue mq=mqinfor.Open(MSMQ.MQACCESS.MQ_RECEIVE_ACCESS.GetHashCode(),MSMQ.MQSHARE.MQ_DENY_NONE.GetHashCode());
MSMQ.MSMQTransactionClass MQ_NO_TRANSACTION=new MSMQTransactionClass();
object a=MQ_NO_TRANSACTION;
bool WantDestinationQueue=false;
object b=WantDestinationQueue;
bool WantBody =true;
object c=WantBody;
long ReceiveTimeout =100;
object d=ReceiveTimeout;
bool WantConnectorType=false;
object e1=WantConnectorType;
MSMQ.MSMQMessage msg=mq.Receive(ref a,ref b,ref c,ref d,ref e1);
this.txtrece.Text=DateTime.Now.ToString() + " " + msg.Body.ToString();
}
catch(Exception e2)
{
MessageBox.Show(e2.Message);
}
}
}
}