title: How can I find the message I added in my msmq
body: <p>I wet through <a href="http://fransiscuss.com/2012/06/01/msmq-basic-tutorial/" rel="nofollow">this</a> except that I added it to a windows service like this</p>
  
  <pre><code>public partial class TriggerHostProcesses : ServiceBase
  {
      private const string MESSAGE_QUEUE = @".\Private$\Sample Queue";
      private MessageQueue _queue;
      public TriggerHostProcesses()
      {
          InitializeComponent();
      }
  
      protected override void OnStart(string[] args)
      {
          SendMessage("Hope This Works");
      }
  
      protected override void OnStop()
      {
      }
  
      internal void start()
      {
          OnStart(null);
      }
  
  
      private void SendMessage(string message)
      {
          _queue = new MessageQueue(MESSAGE_QUEUE);
          Message msg = new Message();
          msg.Body = message;
          msg.Label = "Testing " + DateTime.Now.ToString();
          _queue.Send(msg,new MessageQueueTransaction());
      }
  }
  </code></pre>
  
  <p>and to get the message</p>
  
  <pre><code> partial class HostListener : ServiceBase
  {
        private const string MESSAGE_QUEUE = @".\Private$\Sample Queue";
      private MessageQueue _queue;
  
      public HostListener()
      {
          InitializeComponent();
      }
  
      protected override void OnStart(string[] args)
      {
          try
          {
              var myTransaction = new MessageQueueTransaction();
  
              var queue = new MessageQueue(MESSAGE_QUEUE);
              var message = queue.Receive(new TimeSpan(0, 0, 20),myTransaction);
              message.Formatter = new XmlMessageFormatter(
                                  new String[] { "System.String,mscorlib" });
              Console.WriteLine(message.Body.ToString());
          }
          catch(Exception ex)
          {
              Console.WriteLine("No Message");
          }
      }
  
      protected override void OnStop()
      {
          // TODO: Add code here to perform any tear-down necessary to stop your service.
      }
  
      internal void start()
      {
          OnStart(null);
      }
  }
  </code></pre>
  
  <p>in my main I added this </p>
  
  <pre><code>  var ServiceToRun1 = new TriggerHostProcesses();
          var ServiceToRun2 = new HostListener();
  
          if (Environment.UserInteractive)
          {
              // This used to run the service as a console (development phase only)
  
              ServiceToRun1.start();
              ServiceToRun2.start();
  
              Console.WriteLine("Press Enter to terminate ...");
              Console.ReadLine();
  
              ServiceToRun1.Stop();
              ServiceToRun2.Stop();
          }
          else
          {
              ServiceBase.Run(ServiceToRun1);
          }
  </code></pre>
  
  <p>I get the exception <code>Timeout for the requested operation has expired.</code></p>
  
  <p>Can someone please check if they can see what the problem is?</p>