0
Answer

Why cant i read the values from the queue

hemalatha cmr

hemalatha cmr

16y
2.2k
1

Hi, All

I have a program in C# where I am reading all the messages from a MSMQ.

I have declared a class Queue as below

 public class MyQueue
    {
        public static Queue myqueue;
public MyQueue()
        {
            myqueue = new Queue();
 public void PostItem(Hashtable item)
        {
            lock (myqueue)
            {
                myqueue.Enqueue(item);
                if (myqueue.Count == 1)
                {
                    checkcount++;
                    Monitor.Pulse(myqueue);
                   
                }
            }
        }
        public Hashtable GetItem(int maxWait)
        {
            lock (myqueue)
            {
                if (myqueue.Count == 0)
                {
                    if (maxWait == 0)
                        return default(Hashtable);
                    Monitor.Wait(myqueue, maxWait);
                    if (myqueue.Count == 0)
                        return default(Hashtable);
                  
                }
                return (Hashtable) myqueue.Dequeue();
            }
        }

 public void ToDB(object nullvalue)
        {

            MyQueue myqueu = new MyQueue();
            Hashtable hashtable2;
            try
            {
                //int countRecords = 0;
                DataRow dr;
                while (true)
                {
                    hashtable2 = (Hashtable)myqueu.GetItem(5000);
                    if (hashtable2 == null)
                    {
                    }
                  else
                   {
                   }
              }
         }
   }
}

 

I call in the button click event as

ThreadPool.SetMaxThreads(50, 50);
MyQueue myQ = new MyQueue();
ThreadPool.QueueUserWorkItem(new WaitCallback(myQ.ToDB), null);


Now the prblem I face is, all the messages from the MSMQ are getting read, I placed a counter and verified.
I placed the counter in the Post Item.
Whereas only few records were retrieved in GetItem.


eg, If there are 1000 records in the MSMQ, i received all in the Post Item, whereas I could retrieve only 6 or 5 or 7 in the Get Item part.

Where am i going wrong.
Kindly help.

Regards
Hemalatha