private void Manager(object source, PeekCompletedEventArgs asyncResult) { // Connect to the queue. MessageQueue mq = source as MessageQueue; try { // The manager has responsibility to delegate a work to the receiver for incomming messages // The number of the workers can be managed administratively or on the fly. // End the asynchronous peek operation. mq.EndPeek(asyncResult.AsyncResult); // threadpool controller while(true) { // wait for condition (workers are ready, etc.) if(m_EventMgr.WaitOne(NotifyTime * 1000, true) == false) { // timeout handler if(MaxNumberOfWorkers > 0) { string strWarning = string.Format("[{0}]MSMQChannel.Receiver: All Message Workers are busy", ChannelName); WriteLogMsg(strWarning, EventLogEntryType.Warning); // threadpool is closed, try again continue; } else { m_Listening = false; return; } } // threadpool is open break; } // delegate work to the worker MessageWorkerDelegator mwd = new MessageWorkerDelegator(MessageWorker); mwd.BeginInvoke(source, null, null); } catch(Exception ex) { string strErr = string.Format("[{0}]MSMQChannel.Receiver:Mamager failed, error = {1}", ChannelName, ex.Message); WriteLogMsg(strErr, EventLogEntryType.Error); } finally { // Restart the asynchronous peek operation if(m_Listening == true) mq.BeginPeek(); else Trace.WriteLine(string.Format("[{0}]MSMQChannel.Receiver.Manager has been disconnected", ChannelName)); } }
private void Manager(object source, PeekCompletedEventArgs asyncResult) { // Connect to the queue. MessageQueue mq = source as MessageQueue; try { // The manager has responsibility to delegate a work to the receiver for incomming messages // The number of the workers can be managed administratively or on the fly. // End the asynchronous peek operation. mq.EndPeek(asyncResult.AsyncResult); // threadpool controller while (true) { // wait for condition (workers are ready, etc.) if (m_EventMgr.WaitOne(NotifyTime * 1000, true) == false) { // timeout handler if (MaxNumberOfWorkers > 0) { string strWarning = string.Format("[{0}]MSMQChannel.Receiver: All Message Workers are busy", ChannelName); WriteLogMsg(strWarning, EventLogEntryType.Warning); // threadpool is closed, try again continue; } else { m_Listening = false; return; } } // threadpool is open break; } // delegate work to the worker MessageWorkerDelegator mwd = new MessageWorkerDelegator(MessageWorker); mwd.BeginInvoke(source, null, null); } catch (Exception ex) { string strErr = string.Format("[{0}]MSMQChannel.Receiver:Mamager failed, error = {1}", ChannelName, ex.Message); WriteLogMsg(strErr, EventLogEntryType.Error); } finally { // Restart the asynchronous peek operation if (m_Listening == true) { mq.BeginPeek(); } else { Trace.WriteLine(string.Format("[{0}]MSMQChannel.Receiver.Manager has been disconnected", ChannelName)); } } }