473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Why isnt my Queue reading properly

375 256MB
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
Expand|Select|Wrap|Line Numbers
  1.  public class MyQueue
  2.     {
  3.         public static Queue myqueue;
  4. public MyQueue()
  5.         {
  6.             myqueue = new Queue();
  7.  public void PostItem(Hashtable item)
  8.         {
  9.             lock (myqueue)
  10.             {
  11.                 myqueue.Enqueue(item);
  12.                 if (myqueue.Count == 1)
  13.                 {
  14.                     checkcount++;
  15.                     Monitor.Pulse(myqueue);
  16.  
  17.                 }
  18.             }
  19.         }
  20.         public Hashtable GetItem(int maxWait)
  21.         {
  22.             lock (myqueue)
  23.             {
  24.                 if (myqueue.Count == 0)
  25.                 {
  26.                     if (maxWait == 0)
  27.                         return default(Hashtable);
  28.                     Monitor.Wait(myqueue, maxWait);
  29.                     if (myqueue.Count == 0)
  30.                         return default(Hashtable);
  31.  
  32.                 }
  33.                 return (Hashtable) myqueue.Dequeue();
  34.             }
  35.         }
  36.  
  37.  public void ToDB(object nullvalue)
  38.         {
  39.  
  40.             MyQueue myqueu = new MyQueue();
  41.             Hashtable hashtable2;
  42.             try
  43.             {
  44.                 //int countRecords = 0;
  45.                 DataRow dr;
  46.                 while (true)
  47.                 {
  48.                     hashtable2 = (Hashtable)myqueu.GetItem(5000);
  49.                     if (hashtable2 == null)
  50.                     {
  51.                     }
  52.                   else 
  53.                    {
  54.                    }
  55.               }
  56.          }
  57.    }
  58. }
I call in the button click event as
Expand|Select|Wrap|Line Numbers
  1. ThreadPool.SetMaxThreads(50, 50);
  2. MyQueue myQ = new MyQueue();
  3. 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
cmrhema
Oct 10 '08 #1
1 1240
Plater
7,872 Expert 4TB
Have you tried using the built in .NET Queue object?
Oct 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add...
17
by: Bart Nessux | last post by:
How can one view the contents of a queue? I'd like to verify that the queue has the same number of objects as the list that has been put into it. Also, should one think of a queue as static or...
4
by: Sachin Jagtap | last post by:
Hi, I am getting exception while poping item from queue, I am writing messages coming from client in a queue in one thread and then in other thread i am reading from queue and writing in file....
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
4
by: Macca | last post by:
Hi, I've been reading the online documentation for the System.Collections.Queue object on how to implement a threadsafe Queue object. I understand the basics, by using the wrapper returned by...
7
by: Michael D. Ober | last post by:
When calling Enqueue, the internal array may need to be reallocated. My question is by how much? In the old MFC array classes, you could tell MFC how many additional elements to add to the array...
0
by: neonspark | last post by:
I'm buidling some simple macro functionality for my app so the users can record a sequence of keyboard inputs and replay them reliably via some menu. Originally, I used: protected override bool...
0
by: Eugene Anthony | last post by:
First I leave the server running. Then I open up the client and click the button to send a message to the queue. So when I check the queue its empty. Possible because all the message in the queue...
1
by: VanKha | last post by:
I write a queue program but it doesn't work properly:I enqueue an element and dequeue just after that, but the output is the first value and then many times of "Empty queue.."!Why ?Please help me. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.