- 爱易网页
-
ASP.NET教程
- C#之消息队列的简要说明----自学笔记
日期:2013-04-30 浏览次数:20433 次
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();