c# Message Message Queue Count. - Sharing violation resulted from queue being open already for exclusive receive -


so busy writing watchdog message queue installed on 1 of servers. have application ( 3rd party ) listening on queue , processing messages. want count on , if message reach example 1500 send email. code works except need close 3rd party app use message queue. queue names exist. work fine.

public void getprivatequeues() {     messagequeue[] queuelist =     messagequeue.getprivatequeuesbymachine(".");      foreach (messagequeue queueitem in queuelist)     {         i++;          myprivatequeues.add(queueitem.path);          count(queueitem.path);     }      return; } 

so when count of queue

public void count(string path) {      messagequeue queue = new messagequeue(path);     messageenumerator messageenumerator = queue.getmessageenumerator2();     int iii = 0;     while (messageenumerator.movenext())     {        iii++;     }      myprivatequeuescount.add(iii);     return;//i; } 

i error.

system.messaging.messagequeueexception (0x80004005): sharing violation resulted queue being open exclusive receive.

how can go reading queue count without trying exclusive access on it. need count it.

thank

regards

i used performance counter read queue. working dream now!

added catch exception. when queue blank. write 0. performance counter gives error on blank queue.

       public void count(string path)     {              path = path.remove(0, 21);          try        {             performancecounter queuecounter = new performancecounter(              "msmq queue",              "messages in queue",             @path);               console.writeline("queue contains {0} messages",                 queuecounter.nextvalue().tostring());             myprivatequeuescount.add((int)queuecounter.nextvalue());          }         catch (exception exc)         {             myprivatequeuescount.add(0);         }          return;     } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -