• 大小: 58KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: 其他
  • 标签: MSMQ  

资源简介

http://blog.csdn.net/whuarui2010/article/details/50463552 应用场景&优势,与SyncFramework比较,工作中使用场景,专用队列,架构方案(图)和代码实例

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Messaging;
using System.Threading;
using System.IO;

namespace MessageQueueDemo
{
    public partial class Form1 : Form
    {
        public Form1 ()
        {
            InitializeComponent();
        }

        private void button1_Click (object sender EventArgs e)
        {
            // Open queue
            System.Messaging.MessageQueue queue=new System.Messaging.MessageQueue(“FormatName:Direct=OS:Client01-PC\\private$\\queue“);
            //System.Messaging.MessageQueue queue=new System.Messaging.MessageQueue(“.\\Private$\\queue“);

            // Create message
            System.Messaging.Message message=new System.Messaging.Message();
            message.Body=textBox1.Text.Trim();
            message.Formatter=new System.Messaging.xmlMessageFormatter(new Type[] { typeof(string) });

            // Put message into queue
            queue.Send(message);
        }

        private void button2_Click (object sender EventArgs e)
        {
            System.Messaging.MessageQueue queue=new System.Messaging.MessageQueue(“.\\Private$\\queue“);

            //// Receive message 同步的Receive方法阻塞当前执行线程,直到一个message可以得到
            //System.Messaging.Message message = queue.Receive();
            //message.Formatter = new System.Messaging.xmlMessageFormatter(new Type[] { typeof(string) });
            //textBox2.Text += message.Body.ToString();

            queue.ReceiveCompleted += new ReceiveCompletedEventHandler(messageQueue_ReceiveCompleted);
            queue.BeginReceive();
            this.button2.Enabled = false;
        }
        delegate void SetTextCallback(string text);
        private void SetText(string text)
        {
            if (this.textBox2.InvokeRequired)
            {
                while (!this.textBox2.IsHandleCreated)
                {
                    //解决窗体关闭时出现“访问已释放句柄“的异常
                    if (this.textBox2.Disposing || this.textBox2.IsDisposed)
                        return;
                }
                SetTextCallback d = new SetTextCallback(SetText);
                this.textBox2.Invoke(d new object[] { text });
            }
            else
            {
                this.textBox2.Text += text;
            }
        }
        private void messageQueue_ReceiveCompleted (object sender ReceiveCompletedEventArgs e)
        {
            try
            {
                MessageQueue mq=sender as MessageQueue;
                if(null!=mq)
                {
                    System.Messaging.Message message = mq.EndReceive(e.AsyncResult);
                    message.Formatter = new System.Messaging.xmlMessageFormatter(new Type[] { typeof(string) });
                    var appendString= message.Body.ToString();
              

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     31232  2016-01-13 16:32  MessageQueueDemo\.vs\MessageQueueDemo - 副本\v14\.suo

     文件        144  2016-01-13 10:07  MessageQueueDemo\MessageQueueDemo\app.config

     文件      10752  2016-01-13 16:39  MessageQueueDemo\MessageQueueDemo\bin\Debug\MessageQueueDemo.exe

     文件        144  2016-01-13 10:07  MessageQueueDemo\MessageQueueDemo\bin\Debug\MessageQueueDemo.exe.config

     文件      22016  2016-01-13 16:39  MessageQueueDemo\MessageQueueDemo\bin\Debug\MessageQueueDemo.pdb

     文件      22688  2016-01-13 16:14  MessageQueueDemo\MessageQueueDemo\bin\Debug\MessageQueueDemo.vshost.exe

     文件        144  2016-01-13 10:07  MessageQueueDemo\MessageQueueDemo\bin\Debug\MessageQueueDemo.vshost.exe.config

     文件        490  2015-06-04 12:48  MessageQueueDemo\MessageQueueDemo\bin\Debug\MessageQueueDemo.vshost.exe.manifest

     文件       3288  2016-01-13 16:15  MessageQueueDemo\MessageQueueDemo\Form1.cs

     文件       3628  2016-01-11 15:09  MessageQueueDemo\MessageQueueDemo\Form1.Designer.cs

     文件       5817  2016-01-11 15:09  MessageQueueDemo\MessageQueueDemo\Form1.resx

     文件       3861  2016-01-13 16:31  MessageQueueDemo\MessageQueueDemo\MessageQueueDemo.csproj

     文件       5420  2016-01-12 15:56  MessageQueueDemo\MessageQueueDemo\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7116  2016-01-13 16:31  MessageQueueDemo\MessageQueueDemo\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1092  2016-01-13 16:39  MessageQueueDemo\MessageQueueDemo\obj\x86\Debug\MessageQueueDemo.csproj.FileListAbsolute.txt

     文件        976  2016-01-13 16:39  MessageQueueDemo\MessageQueueDemo\obj\x86\Debug\MessageQueueDemo.csproj.GenerateResource.Cache

     文件       2361  2016-01-13 16:39  MessageQueueDemo\MessageQueueDemo\obj\x86\Debug\MessageQueueDemo.csprojResolveAssemblyReference.cache

     文件      10752  2016-01-13 16:39  MessageQueueDemo\MessageQueueDemo\obj\x86\Debug\MessageQueueDemo.exe

     文件        180  2016-01-13 16:39  MessageQueueDemo\MessageQueueDemo\obj\x86\Debug\MessageQueueDemo.Form1.resources

     文件      22016  2016-01-13 16:39  MessageQueueDemo\MessageQueueDemo\obj\x86\Debug\MessageQueueDemo.pdb

     文件        180  2016-01-13 16:39  MessageQueueDemo\MessageQueueDemo\obj\x86\Debug\MessageQueueDemo.Properties.Resources.resources

     文件       3584  2016-01-13 15:36  MessageQueueDemo\MessageQueueDemo\obj\x86\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        498  2016-01-11 14:02  MessageQueueDemo\MessageQueueDemo\Program.cs

     文件       1382  2016-01-11 14:02  MessageQueueDemo\MessageQueueDemo\Properties\AssemblyInfo.cs

     文件       2872  2016-01-13 10:07  MessageQueueDemo\MessageQueueDemo\Properties\Resources.Designer.cs

     文件       5612  2016-01-11 14:02  MessageQueueDemo\MessageQueueDemo\Properties\Resources.resx

     文件       1116  2016-01-13 10:07  MessageQueueDemo\MessageQueueDemo\Properties\Settings.Designer.cs

     文件        249  2016-01-11 14:02  MessageQueueDemo\MessageQueueDemo\Properties\Settings.settings

     文件        890  2016-01-13 15:33  MessageQueueDemo\MessageQueueDemo - 副本.sln

     文件        890  2016-01-11 14:02  MessageQueueDemo\MessageQueueDemo.sln

............此处省略17个文件信息

评论

共有 条评论