<i id='zwpIX'><tr id='zwpIX'><dt id='zwpIX'><q id='zwpIX'><span id='zwpIX'><b id='zwpIX'><form id='zwpIX'><ins id='zwpIX'></ins><ul id='zwpIX'></ul><sub id='zwpIX'></sub></form><legend id='zwpIX'></legend><bdo id='zwpIX'><pre id='zwpIX'><center id='zwpIX'></center></pre></bdo></b><th id='zwpIX'></th></span></q></dt></tr></i><div id='zwpIX'><tfoot id='zwpIX'></tfoot><dl id='zwpIX'><fieldset id='zwpIX'></fieldset></dl></div>
  • <legend id='zwpIX'><style id='zwpIX'><dir id='zwpIX'><q id='zwpIX'></q></dir></style></legend>

    <small id='zwpIX'></small><noframes id='zwpIX'>

      <bdo id='zwpIX'></bdo><ul id='zwpIX'></ul>

    1. <tfoot id='zwpIX'></tfoot>

        如何为 MSMQ 创建 C# 侦听器服务作为 Windows 服务

        How to Create a C# Listener Service for MSMQ as a Windows Service(如何为 MSMQ 创建 C# 侦听器服务作为 Windows 服务)

        <small id='38Y0h'></small><noframes id='38Y0h'>

          <bdo id='38Y0h'></bdo><ul id='38Y0h'></ul>

        • <tfoot id='38Y0h'></tfoot>
          <i id='38Y0h'><tr id='38Y0h'><dt id='38Y0h'><q id='38Y0h'><span id='38Y0h'><b id='38Y0h'><form id='38Y0h'><ins id='38Y0h'></ins><ul id='38Y0h'></ul><sub id='38Y0h'></sub></form><legend id='38Y0h'></legend><bdo id='38Y0h'><pre id='38Y0h'><center id='38Y0h'></center></pre></bdo></b><th id='38Y0h'></th></span></q></dt></tr></i><div id='38Y0h'><tfoot id='38Y0h'></tfoot><dl id='38Y0h'><fieldset id='38Y0h'></fieldset></dl></div>
        • <legend id='38Y0h'><style id='38Y0h'><dir id='38Y0h'><q id='38Y0h'></q></dir></style></legend>

                <tbody id='38Y0h'></tbody>

                1. 本文介绍了如何为 MSMQ 创建 C# 侦听器服务作为 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我首先要说我不是 .NET 开发人员,但我被投入到一个项目中,我需要使用 MSMQ,以便经典的 ASP Web 应用程序可以将消息发送到处理处理的 C# Windows 服务.我有将其他消息队列与其他语言集成的经验,但就像我提到的,我在 .NET 和 Windows 开发方面没有太多经验,因此非常感谢一些指导.

                  I'll start by saying I'm not a .NET developer, but have been thrown into a project where I need to use MSMQ so a classic ASP web application can send messages to a C# Windows Service that handles the processing. I have experience integrating other message queues with other languages, but like I mentioned, I don't have much experience with .NET and Windows development so some guidance would be much appreciated.

                  这是我的问题...

                  1. 有人可以提供一些基本的 C# 代码来侦听现有的 MSMQ 队列并通过执行一些简单的操作(例如将当前时间戳写入日志文件或发送电子邮件)来响应新消息?

                  1. Could someone provide some basic C# code that listens to an existing MSMQ queue and responds to the new message by doing something simple like writing the current timestamp to a log file or sending an email?

                  如何在 Visual Studio .NET 中打包此代码以创建和安装 Windows 服务?(应该是什么类型的项目等等,我用的是Visual C# 2010 Express.)

                  How do I package this code up in Visual Studio .NET to create and install a Windows Service? (What type of project should it be, etc. I'm using Visual C# 2010 Express.)

                  最后,我不确定我需要使用哪个版本和/或实现的 MSMQ 来满足我对经典 ASP 的要求.我认为 COM 版本是我需要的,但我也阅读了新的 WCF 版本,以及 3.0 和 4.0 之间的差异.有人可以指导我应该使用哪个版本吗?

                  Finally, I'm not sure which version and/or implementation of MSMQ I need to be using for my requirements with classic ASP. I think the COM version is what I need, but I've also read about a new WCF version, as well as differences between 3.0 and 4.0. Could someone please give me direction on which version I should be using?

                  非常感谢!

                  推荐答案

                  您可以使用以下代码在给定队列上等待消息(您想在您的计算机上使用名为 SomeQueue 的私有队列,命名为 ComputerName => QueueName= @"计算机名private$SomeQueue")

                  You can wait for a message on a given queue using the following code (You want to use the private queue named SomeQueue on your computer, named ComputerName => QueueName = @"ComputerNameprivate$SomeQueue")

                      public void AsyncWatchQueue(object encapsulatedQueueName)
                      {
                          Message newMessage;
                          MessageQueue queue;
                  
                          string queueName = encapsulatedQueueName as string;
                          if (queueName == null)
                              return;
                  
                          try
                          {
                              if (!MessageQueue.Exists(queueName))
                                  MessageQueue.Create(queueName);
                              else
                              {
                                  queue = new MessageQueue(queueName);
                  
                                  if (queue.CanRead)
                                      newMessage = queue.Receive();
                              }
                              HandleNewMessage(newMessage); // Do something with the message
                          }
                          // This exception is raised when the Abort method 
                          // (in the thread's instance) is called
                          catch (ThreadAbortException e) 
                          {
                              //Do thread shutdown
                          }
                          finally
                          {
                              queue.Dispose();
                          }
                      }
                  

                  注意:Receove 方法将一直阻塞,直到收到一条消息,此时它将从队列中删除该消息并返回.

                  Note: the Receove method will block untill a message is received at which point it'll remove the message from the queue and return it.

                  为多线程部分的实现添加了代码(并重命名了上述方法签名)

                  edit: added code for the implementation of the multithreaded portion (and renamed the above method signature)

                  线程创建代码:

                          public Thread AddWatchingThread(string QueueName)
                      {
                          Thread Watcher = 
                              new Thread(new ParameterizedThreadStart(AsyncWatchQueue));
                          Watcher.Start(QueueName);
                          // The thread instance is used to manipulate (or shutdown the thread)
                          return Watcher; 
                      }
                  

                  请注意,这是未经测试的鳕鱼,只是一个简单的示例

                  I'll just note, that this is untested cod, it's just an quick example

                  这篇关于如何为 MSMQ 创建 C# 侦听器服务作为 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)

                  1. <i id='J0SC7'><tr id='J0SC7'><dt id='J0SC7'><q id='J0SC7'><span id='J0SC7'><b id='J0SC7'><form id='J0SC7'><ins id='J0SC7'></ins><ul id='J0SC7'></ul><sub id='J0SC7'></sub></form><legend id='J0SC7'></legend><bdo id='J0SC7'><pre id='J0SC7'><center id='J0SC7'></center></pre></bdo></b><th id='J0SC7'></th></span></q></dt></tr></i><div id='J0SC7'><tfoot id='J0SC7'></tfoot><dl id='J0SC7'><fieldset id='J0SC7'></fieldset></dl></div>
                    • <tfoot id='J0SC7'></tfoot>

                        <bdo id='J0SC7'></bdo><ul id='J0SC7'></ul>

                          <small id='J0SC7'></small><noframes id='J0SC7'>

                          <legend id='J0SC7'><style id='J0SC7'><dir id='J0SC7'><q id='J0SC7'></q></dir></style></legend>
                            <tbody id='J0SC7'></tbody>