title: How to create C# program that sends to local message queue.
body: <p>I have a C# Program that is attempting to send to my own local Windows message queue.  I have installed message queue and out of desperation gave all access rights to "Everyone" on both the Message Queue itself and the Public queue that I'm trying to write to.  I have a form which has two text boxes and two buttons.  One pair for sending and another pair for receiving.  I click send and get no errors, it can detect that there is in fact a message queue of that name.  But the send method seems to go off without actually getting it into the queue.    Thanks for any help!  Here is the code:</p>
  
  <pre><code>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;
  
  namespace WindowsFormsApplication1
  {
  public partial class Form1 : Form
  {
      public MessageQueue myNewPublicQueue;
      private static object lockObject = new object();
      /// &lt;summary&gt;
      /// 
      /// &lt;/summary&gt;
      public Form1()
      {
          InitializeComponent();
      }
  
      /// &lt;summary&gt;
      /// 
      /// &lt;/summary&gt;
      /// &lt;param name="sender"&gt;&lt;/param&gt;
      /// &lt;param name="e"&gt;&lt;/param&gt;
      private void buttoSend_Click(object sender, EventArgs e)
      {
          if (MessageQueue.Exists(@".\queuename"))
          {
              myNewPublicQueue = new System.Messaging.MessageQueue(@".\queuename");
              System.Messaging.Message mm = new System.Messaging.Message();
              mm.Body = textBoxSend.Text;
              mm.Label = "First Test Message";
              myNewPublicQueue.Send(mm);
  
          }
  
      }
  
      private void buttonGet_Click(object sender, EventArgs e)
      {
          myNewPublicQueue.ReceiveCompleted += new          ReceiveCompletedEventHandler(queue_ReceiveCompleted);
  
          // Start listening.
          myNewPublicQueue.BeginReceive();
  
      }
      private void queue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
      {
  
  
          lock (lockObject)
          {
              // The message is plain text.
              string text = (string)e.Message.Body;
              Console.WriteLine("Message received: " + text);
              textBoxGet.Text = text;
          }
  
          // Listen for the next message.
          myNewPublicQueue.BeginReceive();
      }
      public enum MessageType
      {
          MESSAGE_TYPE_PLAIN_TEXT = 0,
          MESSAGE_TYPE_HELLO_WORLD = 1
      };
  
      private void Form1_Load(object sender, EventArgs e)
      {
  
      }
  
  
  
  
  
      }
  }
  </code></pre>