- 浏览: 1440237 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (1607)
- asp,asp.net.c# (1)
- java,j2ee (43)
- oracle 相关配置 (12)
- sql (8)
- mongodb (6)
- java (42)
- j2ee (41)
- jar (24)
- sqlite (3)
- mysql (5)
- oracle (1)
- php教程 (2)
- jar包下载 (23)
- mongodb教程 (10)
- mongodb在线教程 (9)
- android开发 (1)
- 手机开发 (1)
- sqlite教程 (4)
- mysql在线教程 (3)
- mysql基础教程 (3)
- struts官网 (1)
- spring官网 (1)
- mongodb高级教程 (11)
- mysql触发器 (1)
- jquery (1)
- bootstrap (1)
- jfinal (1)
- nutz (1)
- 网络推广 (0)
最新评论
-
呵呵6666:
精通JFinal实战:http://www.roncoo.co ...
java框架利器jfinal框架,你应该知道的!!! -
游其是你:
拜托,打广告也专业点行不行
nutz在线教程,不妨看一下,对你应该会有所帮助!!! -
59biye:
11miao 写道看了一下,要是有个例子就更好了
nutz在线教程,不妨看一下,对你应该会有所帮助!!! -
11miao:
看了一下,要是有个例子就更好了
nutz在线教程,不妨看一下,对你应该会有所帮助!!! -
骨之灵魂:
11miao 写道有点深奥,有点看不太懂,呵呵!!!
java规则引擎你应该知道的几点东西,不妨来看看呦!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Messaging ;
using System.Threading ;
namespace WinMsmq
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
static ManualResetEvent signal = new ManualResetEvent(false);
static ManualResetEvent pubRecvieSignal=new ManualResetEvent(false);
private System.Messaging.MessageQueue mq=null;
private readonly string qryname=@"";
private MessageQueue msq=null;
private MessageQueue pubMsq=null;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button sendToPub;
private System.Windows.Forms.Button readFromPub;
private System.Windows.Forms.Button Creaet;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button delPubmsg;
private System.Windows.Forms.Button srPub;
private System.Data.SqlClient.SqlConnection sqlConnection1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.qryname=System.Configuration.ConfigurationSettings.AppSettings["pubMsmqQryName"];
if(MessageQueue.Exists(qryname))
{
this.pubMsq=new MessageQueue(qryname,true);
}
else
{
this.pubMsq=System.Messaging.MessageQueue.Create(qryname,true);
}
this.richTextBox1.AppendText("==================\r\n");
this.richTextBox1.AppendText(this.pubMsq .QueueName +":公共队列创建成功!\r\n");
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button4 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.Creaet = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.srPub = new System.Windows.Forms.Button();
this.delPubmsg = new System.Windows.Forms.Button();
this.readFromPub = new System.Windows.Forms.Button();
this.sendToPub = new System.Windows.Forms.Button();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 56);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "SendMsg";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(8, 16);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "CreateMsmq";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(8, 104);
this.button3.Name = "button3";
this.button3.TabIndex = 2;
this.button3.Text = "ReadMsg";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// richTextBox1
//
this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.richTextBox1.Location = new System.Drawing.Point(0, 152);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(640, 188);
this.richTextBox1.TabIndex = 3;
this.richTextBox1.Text = "richTextBox1";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Location = new System.Drawing.Point(16, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(144, 136);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "非事务";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button4);
this.groupBox2.Controls.Add(this.button7);
this.groupBox2.Controls.Add(this.Creaet);
this.groupBox2.Controls.Add(this.button6);
this.groupBox2.Controls.Add(this.button5);
this.groupBox2.Location = new System.Drawing.Point(184, 0);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(240, 136);
this.groupBox2.TabIndex = 5;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "事务性";
//
// button4
//
this.button4.Location = new System.Drawing.Point(168, 80);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(56, 48);
this.button4.TabIndex = 5;
this.button4.Text = "CreateMsmqWithTran";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button7
//
this.button7.Location = new System.Drawing.Point(16, 104);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(136, 23);
this.button7.TabIndex = 4;
this.button7.Text = "ClearMsgOfRichTxtBox";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// Creaet
//
this.Creaet.Location = new System.Drawing.Point(144, 32);
this.Creaet.Name = "Creaet";
this.Creaet.Size = new System.Drawing.Size(80, 40);
this.Creaet.TabIndex = 3;
this.Creaet.Text = "异步读取消息";
this.Creaet.Click += new System.EventHandler(this.Read);
//
// button6
//
this.button6.Location = new System.Drawing.Point(16, 72);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(104, 23);
this.button6.TabIndex = 2;
this.button6.Text = "ReadMsgTran";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(16, 32);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(104, 24);
this.button5.TabIndex = 1;
this.button5.Text = "SendMsgTran";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// groupBox3
//
this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox3.Controls.Add(this.srPub);
this.groupBox3.Controls.Add(this.delPubmsg);
this.groupBox3.Controls.Add(this.readFromPub);
this.groupBox3.Controls.Add(this.sendToPub);
this.groupBox3.Location = new System.Drawing.Point(432, 0);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(208, 136);
this.groupBox3.TabIndex = 6;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "公共队列";
//
// srPub
//
this.srPub.Location = new System.Drawing.Point(144, 72);
this.srPub.Name = "srPub";
this.srPub.Size = new System.Drawing.Size(56, 48);
this.srPub.TabIndex = 4;
this.srPub.Text = "检索公共队列";
this.srPub.Click += new System.EventHandler(this.srPub_Click);
//
// delPubmsg
//
this.delPubmsg.Location = new System.Drawing.Point(8, 96);
this.delPubmsg.Name = "delPubmsg";
this.delPubmsg.Size = new System.Drawing.Size(112, 24);
this.delPubmsg.TabIndex = 3;
this.delPubmsg.Text = "DeletePubMsmg";
this.delPubmsg.Click += new System.EventHandler(this.delPubmsg_Click);
//
// readFromPub
//
this.readFromPub.Location = new System.Drawing.Point(8, 64);
this.readFromPub.Name = "readFromPub";
this.readFromPub.Size = new System.Drawing.Size(128, 24);
this.readFromPub.TabIndex = 2;
this.readFromPub.Text = "ReadMsgFromPubMsmg";
this.readFromPub.Click += new System.EventHandler(this.readFromPub_Click);
//
// sendToPub
//
this.sendToPub.Location = new System.Drawing.Point(8, 32);
this.sendToPub.Name = "sendToPub";
this.sendToPub.Size = new System.Drawing.Size(144, 24);
this.sendToPub.TabIndex = 1;
this.sendToPub.Text = "SendMsgToPubMsmq";
this.sendToPub.Click += new System.EventHandler(this.sendToPub_Click);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=DHZ;packet size=4096;integrated security=SSPI;data source=\"DHZ\\DHZ" +
"\";persist security info=False;initial catalog=Northwind";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(648, 349);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
if(MessageQueue.Exists(@".\private$\dhzOrderMgmt"))
{
this.mq=new MessageQueue(@".\private$\dhzOrderMgmt");
}
else
{
this.mq=MessageQueue.Create(@".\private$\dhzOrderMgmt",false);
}
this.richTextBox1.AppendText("==================\r\n");
this.richTextBox1.AppendText(mq.QueueName +":创建成功!\r\n");
}
private void button1_Click(object sender, System.EventArgs e)
{
Od od=new Od("代汉章","南昌",DateTime.Now.ToLongTimeString ());
if(this.mq.Transactional)
{
this.mq.Send(od,new System.Messaging.MessageQueueTransaction ());
}
else
{
this.mq.Send(od);
}
this.richTextBox1.AppendText("发送成功!\r\n");
}
private void button2_Click(object sender, System.EventArgs e)
{
if(MessageQueue.Exists(@".\private$\dhzOrderMgmt"))
{
this.mq=new MessageQueue(@".\private$\dhzOrderMgmt");
}
else
{
this.mq=MessageQueue.Create(@".\private$\dhzOrderMgmt",false);
}
this.richTextBox1.AppendText("==================\r\n");
this.richTextBox1.AppendText(mq.QueueName +":创建成功!\r\n");
}
private void button3_Click(object sender, System.EventArgs e)
{
if(this.mq!=null)
{
System.Messaging.MessageEnumerator msg=this.mq.GetMessageEnumerator ();
while(msg.MoveNext ())
{
System.Messaging .Message oc=msg.Current ;
Od od=oc.Body as Od ;
this.richTextBox1.AppendText(od.Name +":"+od.City +":"+od.Time +";\r\n");
}
}
}
private void button4_Click(object sender, System.EventArgs e)
{
if(MessageQueue.Exists(@".\private$\dhzTrans"))
{
this.msq =new MessageQueue(@".\private$\dhzTrans");
}
else
{
this.msq=MessageQueue.Create(@".\private$\dhzTrans",true);
}
this.richTextBox1.AppendText("==================\r\n");
this.richTextBox1.AppendText(msq.QueueName +":创建成功!\r\n");
}
private void button5_Click(object sender, System.EventArgs e)
{
this.msq=new MessageQueue(@".\private$\dhzTrans");
if(this.msq.Transactional)
{
Od od=new Od("万卿","景德镇",DateTime.Now.ToString("u"));
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();
myTransaction.Begin();
msq.Send(od,myTransaction);
myTransaction.Commit();
this.richTextBox1.AppendText("OK!发送成功:"+od.Time+"\r\n" );
}
}
private void button6_Click(object sender, System.EventArgs e)
{
this.msq=new MessageQueue(@".\private$\dhzTrans");
if(this.msq .Transactional )
{
MessageQueueTransaction myTransaction = new MessageQueueTransaction();
this.msq.Formatter=new System.Messaging.XmlMessageFormatter (new Type[]{Type.GetType("WinMsmq.Od" )});
myTransaction.Begin();
System.Messaging.Message ms=msq.Receive(myTransaction);
Od od=ms.Body as Od ;
this.richTextBox1.AppendText(od.Name +":"+od.City +":"+od.Time +";\r\n");
myTransaction.Commit();
this.richTextBox1.AppendText("OK!发送成功\r\n");
}
}
private void Read(object sender, System.EventArgs e)
{
this.msq=new MessageQueue(@".\private$\dhzTrans");
if(this.msq.Transactional)
{
MessageQueueTransaction myTransaction = new MessageQueueTransaction();
msq.ReceiveCompleted += new ReceiveCompletedEventHandler(MyReceiveCompleted);
this.msq.Formatter=new System.Messaging.XmlMessageFormatter (new Type[]{Type.GetType("WinMsmq.Od" )});
myTransaction.Begin();
msq.BeginReceive();
Form1.signal.WaitOne ();
myTransaction.Commit ();
}
}
private void MyReceiveCompleted(Object source,ReceiveCompletedEventArgs asyncResult)
{
try
{
MessageQueue mq = (MessageQueue)source;
System.Messaging .Message m = mq.EndReceive(asyncResult.AsyncResult);
Form1.signal.Set ();
Od od=m.Body as Od ;
this.richTextBox1.AppendText ("Read:"+od.Name +":"+od.City +":"+od.Time +"\r\n"+"插入数据库完成\r\n");
mq.BeginReceive();
}
catch(MessageQueueException c)
{
this.richTextBox1.AppendText("Error:"+c.Message +"\r\n");
this.button5.Enabled=false;
}
// Handle other exceptions.
}
private void button7_Click(object sender, System.EventArgs e)
{
this.richTextBox1.Clear ();
}
private void delPubmsg_Click(object sender, System.EventArgs e)
{
//删除创建的公共队列
System.Messaging.MessageQueue.Delete (qryname);
}
private void srPub_Click(object sender, System.EventArgs e)
{
MessageQueue[] mq=System.Messaging.MessageQueue.GetPublicQueuesByMachine ("dhz");
for(int i=0;i<mq.Length ;i++)
{
this.richTextBox1.AppendText(mq[i].QueueName +":\r\n");
}
}
private void sendToPub_Click(object sender, System.EventArgs e)
{
if(this.pubMsq==null)
this.pubMsq=new MessageQueue(this.qryname );
if(this.pubMsq.Transactional )
{
Od od=new Od("万卿","景德镇",DateTime.Now.ToString("u"));
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();
myTransaction.Begin();
pubMsq.Send(od,myTransaction);
myTransaction.Commit();
}
}
private void readFromPub_Click(object sender, System.EventArgs e)
{
this.pubMsq=new MessageQueue(this.qryname );
if(this.pubMsq.Transactional)
{
MessageQueueTransaction myTransaction = new MessageQueueTransaction();
pubMsq.ReceiveCompleted += new ReceiveCompletedEventHandler(MyReceiveCompleted);
this.pubMsq.Formatter=new System.Messaging.XmlMessageFormatter (new Type[]{Type.GetType("WinMsmq.Od" )});
myTransaction.Begin();
pubMsq.BeginReceive();
Form1.signal.WaitOne ();
myTransaction.Commit ();
}
}
}
}
/////////////////////////================
public class Od
{
public Od()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public Od(string na,string cty,string timestr)
{
this.name=na;
this.city=cty;
this.time=timestr;
}
private string time="";
private string name;
private string city;
public string Name
{
get{return this.name ;}
set{this.name=value;}
}
public string City
{
get{return this.city ;}
set{this.city=value;}
}
public string Time
{
get{return this.time ;}
set{this.time=value;}
}
}
=======================App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!--ComputerName-->
<!--dhz:是域控制器所在的计算机名:-->
<add key="QcName" value="dhz\FormatName:Public=620B1BFB-18E9-4d80-B869-FF6FB2DFDD08"></add>
</appSettings>
</configuration>
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Messaging ;
using System.Threading ;
namespace WinMsmq
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
static ManualResetEvent signal = new ManualResetEvent(false);
static ManualResetEvent pubRecvieSignal=new ManualResetEvent(false);
private System.Messaging.MessageQueue mq=null;
private readonly string qryname=@"";
private MessageQueue msq=null;
private MessageQueue pubMsq=null;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button sendToPub;
private System.Windows.Forms.Button readFromPub;
private System.Windows.Forms.Button Creaet;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button delPubmsg;
private System.Windows.Forms.Button srPub;
private System.Data.SqlClient.SqlConnection sqlConnection1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.qryname=System.Configuration.ConfigurationSettings.AppSettings["pubMsmqQryName"];
if(MessageQueue.Exists(qryname))
{
this.pubMsq=new MessageQueue(qryname,true);
}
else
{
this.pubMsq=System.Messaging.MessageQueue.Create(qryname,true);
}
this.richTextBox1.AppendText("==================\r\n");
this.richTextBox1.AppendText(this.pubMsq .QueueName +":公共队列创建成功!\r\n");
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button4 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.Creaet = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.srPub = new System.Windows.Forms.Button();
this.delPubmsg = new System.Windows.Forms.Button();
this.readFromPub = new System.Windows.Forms.Button();
this.sendToPub = new System.Windows.Forms.Button();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 56);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "SendMsg";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(8, 16);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "CreateMsmq";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(8, 104);
this.button3.Name = "button3";
this.button3.TabIndex = 2;
this.button3.Text = "ReadMsg";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// richTextBox1
//
this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.richTextBox1.Location = new System.Drawing.Point(0, 152);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(640, 188);
this.richTextBox1.TabIndex = 3;
this.richTextBox1.Text = "richTextBox1";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Location = new System.Drawing.Point(16, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(144, 136);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "非事务";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button4);
this.groupBox2.Controls.Add(this.button7);
this.groupBox2.Controls.Add(this.Creaet);
this.groupBox2.Controls.Add(this.button6);
this.groupBox2.Controls.Add(this.button5);
this.groupBox2.Location = new System.Drawing.Point(184, 0);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(240, 136);
this.groupBox2.TabIndex = 5;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "事务性";
//
// button4
//
this.button4.Location = new System.Drawing.Point(168, 80);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(56, 48);
this.button4.TabIndex = 5;
this.button4.Text = "CreateMsmqWithTran";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button7
//
this.button7.Location = new System.Drawing.Point(16, 104);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(136, 23);
this.button7.TabIndex = 4;
this.button7.Text = "ClearMsgOfRichTxtBox";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// Creaet
//
this.Creaet.Location = new System.Drawing.Point(144, 32);
this.Creaet.Name = "Creaet";
this.Creaet.Size = new System.Drawing.Size(80, 40);
this.Creaet.TabIndex = 3;
this.Creaet.Text = "异步读取消息";
this.Creaet.Click += new System.EventHandler(this.Read);
//
// button6
//
this.button6.Location = new System.Drawing.Point(16, 72);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(104, 23);
this.button6.TabIndex = 2;
this.button6.Text = "ReadMsgTran";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(16, 32);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(104, 24);
this.button5.TabIndex = 1;
this.button5.Text = "SendMsgTran";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// groupBox3
//
this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox3.Controls.Add(this.srPub);
this.groupBox3.Controls.Add(this.delPubmsg);
this.groupBox3.Controls.Add(this.readFromPub);
this.groupBox3.Controls.Add(this.sendToPub);
this.groupBox3.Location = new System.Drawing.Point(432, 0);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(208, 136);
this.groupBox3.TabIndex = 6;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "公共队列";
//
// srPub
//
this.srPub.Location = new System.Drawing.Point(144, 72);
this.srPub.Name = "srPub";
this.srPub.Size = new System.Drawing.Size(56, 48);
this.srPub.TabIndex = 4;
this.srPub.Text = "检索公共队列";
this.srPub.Click += new System.EventHandler(this.srPub_Click);
//
// delPubmsg
//
this.delPubmsg.Location = new System.Drawing.Point(8, 96);
this.delPubmsg.Name = "delPubmsg";
this.delPubmsg.Size = new System.Drawing.Size(112, 24);
this.delPubmsg.TabIndex = 3;
this.delPubmsg.Text = "DeletePubMsmg";
this.delPubmsg.Click += new System.EventHandler(this.delPubmsg_Click);
//
// readFromPub
//
this.readFromPub.Location = new System.Drawing.Point(8, 64);
this.readFromPub.Name = "readFromPub";
this.readFromPub.Size = new System.Drawing.Size(128, 24);
this.readFromPub.TabIndex = 2;
this.readFromPub.Text = "ReadMsgFromPubMsmg";
this.readFromPub.Click += new System.EventHandler(this.readFromPub_Click);
//
// sendToPub
//
this.sendToPub.Location = new System.Drawing.Point(8, 32);
this.sendToPub.Name = "sendToPub";
this.sendToPub.Size = new System.Drawing.Size(144, 24);
this.sendToPub.TabIndex = 1;
this.sendToPub.Text = "SendMsgToPubMsmq";
this.sendToPub.Click += new System.EventHandler(this.sendToPub_Click);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=DHZ;packet size=4096;integrated security=SSPI;data source=\"DHZ\\DHZ" +
"\";persist security info=False;initial catalog=Northwind";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(648, 349);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
if(MessageQueue.Exists(@".\private$\dhzOrderMgmt"))
{
this.mq=new MessageQueue(@".\private$\dhzOrderMgmt");
}
else
{
this.mq=MessageQueue.Create(@".\private$\dhzOrderMgmt",false);
}
this.richTextBox1.AppendText("==================\r\n");
this.richTextBox1.AppendText(mq.QueueName +":创建成功!\r\n");
}
private void button1_Click(object sender, System.EventArgs e)
{
Od od=new Od("代汉章","南昌",DateTime.Now.ToLongTimeString ());
if(this.mq.Transactional)
{
this.mq.Send(od,new System.Messaging.MessageQueueTransaction ());
}
else
{
this.mq.Send(od);
}
this.richTextBox1.AppendText("发送成功!\r\n");
}
private void button2_Click(object sender, System.EventArgs e)
{
if(MessageQueue.Exists(@".\private$\dhzOrderMgmt"))
{
this.mq=new MessageQueue(@".\private$\dhzOrderMgmt");
}
else
{
this.mq=MessageQueue.Create(@".\private$\dhzOrderMgmt",false);
}
this.richTextBox1.AppendText("==================\r\n");
this.richTextBox1.AppendText(mq.QueueName +":创建成功!\r\n");
}
private void button3_Click(object sender, System.EventArgs e)
{
if(this.mq!=null)
{
System.Messaging.MessageEnumerator msg=this.mq.GetMessageEnumerator ();
while(msg.MoveNext ())
{
System.Messaging .Message oc=msg.Current ;
Od od=oc.Body as Od ;
this.richTextBox1.AppendText(od.Name +":"+od.City +":"+od.Time +";\r\n");
}
}
}
private void button4_Click(object sender, System.EventArgs e)
{
if(MessageQueue.Exists(@".\private$\dhzTrans"))
{
this.msq =new MessageQueue(@".\private$\dhzTrans");
}
else
{
this.msq=MessageQueue.Create(@".\private$\dhzTrans",true);
}
this.richTextBox1.AppendText("==================\r\n");
this.richTextBox1.AppendText(msq.QueueName +":创建成功!\r\n");
}
private void button5_Click(object sender, System.EventArgs e)
{
this.msq=new MessageQueue(@".\private$\dhzTrans");
if(this.msq.Transactional)
{
Od od=new Od("万卿","景德镇",DateTime.Now.ToString("u"));
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();
myTransaction.Begin();
msq.Send(od,myTransaction);
myTransaction.Commit();
this.richTextBox1.AppendText("OK!发送成功:"+od.Time+"\r\n" );
}
}
private void button6_Click(object sender, System.EventArgs e)
{
this.msq=new MessageQueue(@".\private$\dhzTrans");
if(this.msq .Transactional )
{
MessageQueueTransaction myTransaction = new MessageQueueTransaction();
this.msq.Formatter=new System.Messaging.XmlMessageFormatter (new Type[]{Type.GetType("WinMsmq.Od" )});
myTransaction.Begin();
System.Messaging.Message ms=msq.Receive(myTransaction);
Od od=ms.Body as Od ;
this.richTextBox1.AppendText(od.Name +":"+od.City +":"+od.Time +";\r\n");
myTransaction.Commit();
this.richTextBox1.AppendText("OK!发送成功\r\n");
}
}
private void Read(object sender, System.EventArgs e)
{
this.msq=new MessageQueue(@".\private$\dhzTrans");
if(this.msq.Transactional)
{
MessageQueueTransaction myTransaction = new MessageQueueTransaction();
msq.ReceiveCompleted += new ReceiveCompletedEventHandler(MyReceiveCompleted);
this.msq.Formatter=new System.Messaging.XmlMessageFormatter (new Type[]{Type.GetType("WinMsmq.Od" )});
myTransaction.Begin();
msq.BeginReceive();
Form1.signal.WaitOne ();
myTransaction.Commit ();
}
}
private void MyReceiveCompleted(Object source,ReceiveCompletedEventArgs asyncResult)
{
try
{
MessageQueue mq = (MessageQueue)source;
System.Messaging .Message m = mq.EndReceive(asyncResult.AsyncResult);
Form1.signal.Set ();
Od od=m.Body as Od ;
this.richTextBox1.AppendText ("Read:"+od.Name +":"+od.City +":"+od.Time +"\r\n"+"插入数据库完成\r\n");
mq.BeginReceive();
}
catch(MessageQueueException c)
{
this.richTextBox1.AppendText("Error:"+c.Message +"\r\n");
this.button5.Enabled=false;
}
// Handle other exceptions.
}
private void button7_Click(object sender, System.EventArgs e)
{
this.richTextBox1.Clear ();
}
private void delPubmsg_Click(object sender, System.EventArgs e)
{
//删除创建的公共队列
System.Messaging.MessageQueue.Delete (qryname);
}
private void srPub_Click(object sender, System.EventArgs e)
{
MessageQueue[] mq=System.Messaging.MessageQueue.GetPublicQueuesByMachine ("dhz");
for(int i=0;i<mq.Length ;i++)
{
this.richTextBox1.AppendText(mq[i].QueueName +":\r\n");
}
}
private void sendToPub_Click(object sender, System.EventArgs e)
{
if(this.pubMsq==null)
this.pubMsq=new MessageQueue(this.qryname );
if(this.pubMsq.Transactional )
{
Od od=new Od("万卿","景德镇",DateTime.Now.ToString("u"));
MessageQueueTransaction myTransaction = new
MessageQueueTransaction();
myTransaction.Begin();
pubMsq.Send(od,myTransaction);
myTransaction.Commit();
}
}
private void readFromPub_Click(object sender, System.EventArgs e)
{
this.pubMsq=new MessageQueue(this.qryname );
if(this.pubMsq.Transactional)
{
MessageQueueTransaction myTransaction = new MessageQueueTransaction();
pubMsq.ReceiveCompleted += new ReceiveCompletedEventHandler(MyReceiveCompleted);
this.pubMsq.Formatter=new System.Messaging.XmlMessageFormatter (new Type[]{Type.GetType("WinMsmq.Od" )});
myTransaction.Begin();
pubMsq.BeginReceive();
Form1.signal.WaitOne ();
myTransaction.Commit ();
}
}
}
}
/////////////////////////================
public class Od
{
public Od()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public Od(string na,string cty,string timestr)
{
this.name=na;
this.city=cty;
this.time=timestr;
}
private string time="";
private string name;
private string city;
public string Name
{
get{return this.name ;}
set{this.name=value;}
}
public string City
{
get{return this.city ;}
set{this.city=value;}
}
public string Time
{
get{return this.time ;}
set{this.time=value;}
}
}
=======================App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!--ComputerName-->
<!--dhz:是域控制器所在的计算机名:-->
<add key="QcName" value="dhz\FormatName:Public=620B1BFB-18E9-4d80-B869-FF6FB2DFDD08"></add>
</appSettings>
</configuration>
相关推荐
### C#数据结构(C#程序员必备):关键知识点解析 #### 一、C#与数据结构结合的意义 **背景介绍**: 随着微软.NET框架的推出,C#作为一种面向对象的编程语言,因其简洁高效的语法特性而迅速受到开发者的青睐。在这一...
Redis是一个高性能的键值存储系统,常用于缓存、消息队列以及数据库功能。C#是.NET框架下的主要编程语言,提供了丰富的库来与Redis进行交互。我们将重点讨论以下几个Redis数据结构及其在C#中的使用:string、set、...
介绍数据结构的基本概念,包括数据结构的定义、分类及其在实际应用中的重要性,并简要介绍C#语言的基础知识,为后续章节的学习打下基础。 2. **第2章至第6章**:详细探讨了线性表、栈和队列、串和数组、树型结构以及...
- **第1章**:介绍了数据结构和算法的基本概念,包括数据结构的定义、分类、算法分析等基础知识,同时简要回顾了C#语言的相关知识,为后续章节的学习打下坚实的基础。 - **第2章至第6章**:依次介绍了线性表、栈和...
本资源包含23种经典的设计模式的C#实现,以下是对这些模式的详细说明: 1. 单例模式(Singleton):确保一个类只有一个实例,并提供全局访问点。在C#中,通常使用静态成员和私有构造函数来实现。 2. 工厂模式...
- **第一章**:介绍数据结构与算法的基本概念,为后续学习打下理论基础,并简要回顾所需的数学和 C# 语言知识。 - **第二章至第六章**:详细讲解线性表、栈、队列、串、数组、树型结构和图结构等常见数据结构及其在 ...
以上就是C#中常见的几种排序算法的简要介绍,通过实际编写和运行这些代码,开发者可以更好地理解每种排序算法的运作机制,并在实际项目中根据需求选择合适的排序方法。这些算法的实现不仅可以提高编程技巧,也有助于...
尽管C#语言已经成为.NET平台上的主流选择之一,但在编写时面临着两个主要挑战: 1. **市场空白**:在当时,使用C#语言讲解数据结构的教材在国内几乎是空白。 2. **技术更新快速**:C#语言及其.NET Framework版本的...
1. **第一章**:介绍数据结构与算法的基本概念,同时简要回顾所需的数学基础知识和C#语言知识。 2. **第二章至第六章**:分别讲述了线性表、栈和队列、串和数组、树型结构、图结构等常用数据结构及其在.NET框架中的...
- C#语言基础:简要回顾C#的基本语法、面向对象特性以及其在数据结构实现中的应用。 2. **第二章:线性表** - 顺序表:一维数组实现,包括插入、删除操作的时间复杂度分析。 - 链表:单链表、双向链表的构造,...
在这个例子中,服务器在12345端口监听,客户端连接并发送消息,服务器接收到消息后回应,然后关闭连接。这只是一个基础的交互,实际应用中可能需要处理多线程、异步操作、错误处理等复杂情况。 在VS2010中,可以...
随着.NET平台的兴起和发展,C#作为一种高效的编程语言,逐渐成为软件开发领域的主流选择之一。本书正是基于这一背景下诞生的,它填补了市场上以C#语言讲解数据结构的空白。 #### 二、C#语言的特点与优势 在深入...
- **C#**:作为微软.NET框架下的主要编程语言之一,C#因其简洁、高效、面向对象等特点受到广泛欢迎。C#不仅支持传统桌面应用程序开发,还适用于Web应用、移动应用乃至游戏开发等多个领域。 #### 二、编写背景及目标...
- **栈和队列**:介绍栈和队列这两种特殊的线性结构,它们的原理、应用场景以及如何利用C#语言实现。 - **串和数组**:探讨字符串和数组这两种基本的数据结构,包括字符串的表示方式、数组的定义及其实现。 - **树型...
1. **第1章:基础知识** - 引入数据结构与算法的基本概念,并简要回顾必要的数学和C#知识。 2. **第2章至第6章** - 深入探讨各种数据结构,包括线性表、栈和队列、字符串和数组、树形结构和图结构,并结合.NET框架中...
- **C#的特点**:C#作为一种面向对象的语言,具有简洁、高效、模板化和标准化等特点,使其成为.NET平台上的首选语言之一。这种语言不仅适用于专业开发者,也适合初学者快速掌握面向对象编程的基础知识。 - **教学...