title: MSMQ: MessageQueue.Close() throws exception -1073741536 at .EndReceive()
body: <p>I'm using <strong>MSMQ</strong> inside a Windows Service.<br />
  When the service is paused, I'd like to <strong>close MSMQ</strong> and reopen it when the service is resumed. <br /></p>
  
  <p>The code looks like this:<br /></p>
  
  <p><strong>OnStart</strong></p>
  
  <pre><code>_mq.ReceiveCompleted += this.ReceiveCompletedHandler;
  _mq.BeginReceive();
  </code></pre>
  
  <p><strong>OnPause</strong></p>
  
  <pre><code>// MessageQueue.ClearConnectionCache();
  _mq.Close();
  </code></pre>
  
  <p><strong>OnContinue</strong></p>
  
  <blockquote>
    <p>same as OnStart</p>
  </blockquote>
  
  <p>Now, this works BUT after <code>.Close()</code> an exception is thrown in the <code>ReceiveCompletedHandler</code>:</p>
  
  <pre><code>private void ReceiveCompletedHandler(object sender, ReceiveCompletedEventArgs e)
  {
      Message message = this.mq.EndReceive(e.AsyncResult); // or e.Message
      // do stuff
  }
  </code></pre>
  
  <p><strong>Exception details:</strong></p>
  
  <p>Type: <code>MessageQueueException</code><br />
  Message: <code>null</code><br />
  ErrorCode: <code>-2147467259</code><br />
  MessageQueueErrorCode: <code>-1073741536</code><br /></p>
  
  <p>How do I <strong>prevent</strong> this <strong>from happening</strong>?<br /></p>