public void LoopThruMessages() { MQGetMessageOptions gmo = new MQGetMessageOptions(); gmo.Options |= MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING; gmo.WaitInterval = 2500; // 2.5 seconds wait time or use MQC.MQEI_UNLIMITED to wait forever MQMessage msg = null; while (running) { try { msg = new MQMessage(); inQ.Get(msg, gmo); System.Console.Out.WriteLine("Message Data: " + msg.ReadString(msg.MessageLength)); } catch (MQException mqex) { if (mqex.Reason == MQC.MQRC_NO_MSG_AVAILABLE) { // no meesage - life is good - loop again } else { running = false; // severe error - time to exit System.Console.Out.WriteLine("MQException CC=" + mqex.CompletionCode + " : RC=" + mqex.ReasonCode); } } catch (System.IO.IOException ioex) { System.Console.Out.WriteLine("ioex=" + ioex); } } try { if (inQ != null) { inQ.Close(); System.Console.Out.WriteLine("Closed queue"); } } catch (MQException mqex) { System.Console.Out.WriteLine("MQException CC=" + mqex.CompletionCode + " : RC=" + mqex.ReasonCode); } try { if (qMgr != null) { qMgr.Disconnect(); System.Console.Out.WriteLine("disconnected from queue manager"); } } catch (MQException mqex) { System.Console.Out.WriteLine("MQException CC=" + mqex.CompletionCode + " : RC=" + mqex.ReasonCode); } }