private void CountQueueMessages(QSetQueueItem queueItem) { //first of all, ensure we have a node to work with QueueItemListViewItemPair itemPair = null; if (_itemPairHashTable.ContainsKey(queueItem.ID)) { itemPair = (QSetMonitorWorker.QueueItemListViewItemPair)_itemPairHashTable[queueItem.ID]; } else { //TODO create icon itemPair = new QueueItemListViewItemPair(queueItem, new ListViewItem(queueItem.Name, (int)Images.IconType.Queue)); for (int subItemCounter = 0; subItemCounter < _COLUMNS; subItemCounter++) { itemPair.ListViewItem.SubItems.Add(string.Empty); } _itemPairHashTable.Add(itemPair.QSetQueueItem.ID, itemPair); Action x = delegate { _monitorListView.Items.Add(itemPair.ListViewItem); }; _monitorListView.Invoke(x); } ManagementObject counter = null; try { counter = new ManagementObject(String.Format("Win32_PerfRawdata_MSMQ_MSMQQueue.name='{0}'", itemPair.QSetQueueItem.Name)); counter.Get(); uint outgoingMessageCount = Convert.ToUInt32(counter.GetPropertyValue("MessagesInQueue")); uint outgoingBytes = Convert.ToUInt32(counter.GetPropertyValue("BytesInQueue")); Action herewegoagain = () => { if (itemPair.ListViewItem.SubItems[(int)SubItemList.OutgoingMessageCount].Text != outgoingMessageCount.ToString()) //note: only do if necessary, to avoid flicker { itemPair.ListViewItem.SubItems[(int)SubItemList.OutgoingMessageCount].Text = outgoingMessageCount.ToString(); } if (itemPair.ListViewItem.SubItems[(int)SubItemList.OutgoingBytes].Text != outgoingBytes.ToString()) //note: only do if necessary, to avoid flicker { itemPair.ListViewItem.SubItems[(int)SubItemList.OutgoingBytes].Text = outgoingBytes.ToString(); } }; _monitorListView.Invoke(herewegoagain); } catch { //exception will occur when cannot get access to performance counters } finally { if (counter != null) { counter.Dispose(); } } }
/// <summary> /// Runs the Q Set monitor. /// </summary> /// <param name="state"></param> private void MonitorQSetWaitCallBack(object state) { bool subscribeToEvents = true; Thread.CurrentThread.Priority = ThreadPriority.Lowest; while (!_isStopRequested) { //update monitor RecurseQSet((QSetModel)state, subscribeToEvents); subscribeToEvents = false; _monitorListView.Invoke(new Action(() => { // Delete any queues which have been removed while (_deleteItemPairQueue.Count > 0) { QueueItemListViewItemPair itemPair = (QueueItemListViewItemPair)_deleteItemPairQueue.Dequeue(); _itemPairHashTable.Remove(itemPair.QSetQueueItem.ID); _monitorListView.Items.Remove(itemPair.ListViewItem); } })); Thread.Sleep(250); } _resetEvent.Set(); }
private void CountQueueMessages(QSetQueueItem queueItem) { //first of all, ensure we have a node to work with QueueItemListViewItemPair itemPair = null; if (_itemPairHashTable.ContainsKey(queueItem.ID)) itemPair = (QSetMonitorWorker.QueueItemListViewItemPair)_itemPairHashTable[queueItem.ID]; else { //TODO create icon itemPair = new QueueItemListViewItemPair(queueItem, new ListViewItem(queueItem.Name, (int)Images.IconType.Queue)); for (int subItemCounter = 0; subItemCounter < _COLUMNS; subItemCounter ++) itemPair.ListViewItem.SubItems.Add(string.Empty); _itemPairHashTable.Add(itemPair.QSetQueueItem.ID, itemPair); Action x = delegate { _monitorListView.Items.Add(itemPair.ListViewItem); }; _monitorListView.Invoke(x); } ManagementObject counter = null; try { counter = new ManagementObject(String.Format("Win32_PerfRawdata_MSMQ_MSMQQueue.name='{0}'", itemPair.QSetQueueItem.Name)); counter.Get(); uint outgoingMessageCount = Convert.ToUInt32(counter.GetPropertyValue("MessagesInQueue")); uint outgoingBytes = Convert.ToUInt32(counter.GetPropertyValue("BytesInQueue")); Action herewegoagain = () => { if (itemPair.ListViewItem.SubItems[(int)SubItemList.OutgoingMessageCount].Text != outgoingMessageCount.ToString()) //note: only do if necessary, to avoid flicker itemPair.ListViewItem.SubItems[(int)SubItemList.OutgoingMessageCount].Text = outgoingMessageCount.ToString(); if (itemPair.ListViewItem.SubItems[(int)SubItemList.OutgoingBytes].Text != outgoingBytes.ToString()) //note: only do if necessary, to avoid flicker itemPair.ListViewItem.SubItems[(int)SubItemList.OutgoingBytes].Text = outgoingBytes.ToString(); }; _monitorListView.Invoke(herewegoagain); } catch { //exception will occur when cannot get access to performance counters } finally { if (counter != null) counter.Dispose(); } }