Link to home
Start Free TrialLog in
Avatar of pointeman
pointemanFlag for United States of America

asked on

Queue Dequeue ArrayList Count 0?

I can successfully Enqueue ArrayList's to a Collections.Queue. Having problem Dequeue-ing ArrayList. I know the Queued ArrayLists contain data by running a foreach at myQueue.cs

[myQueue]
 
internal class myQueue
{
   private static Queue que = Queue.Synchronized(new Queue());

   internal static void Enque(ArrayList list)
   {
         que.Enqueue(list);
   }

    internal static ArrayList Deque()
    {
         return (ArrayList)que.Dequeue();
    }  
}

Every attempt to dequeue the queued ArrayList returns a count of 0, although I know the Queue definitely has ArrayList's queued.

[AnotherClass.cs]

 ArrayList arr = new ArrayList(Que.Deque()); //count=0

 ArrayList arr = new ArrayList(); arrData.AddRange(Que.Deque()); //count=0

 ArrayList arr = Que.Deque();//count=0

 ArrayList arr = (ArrayList)Que.Deque();//count=0

 ArrayList arr = new ArrayList();
 arr = Que.Deque();
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Honestly, I didn't understand, how you created your Queue in anotherclass, and what you have enqueued... Pls more details
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah, indeed... How Idle_Mind enques a list - I can see! :)

I believe the error in the original post - no lists were enqued!
Avatar of pointeman

ASKER

I though it could be a threading issue, but change the Queue into a String and Dequeue works fine.

More details...

1. Windows Service project, NOT winform.
2. Class1.cs successfully Enqueues data to myQueue.cs
3. myQueue.cs successfully writes ArrayList data to logfile using foreach...
4  Class2 uses myQueue.Deque() Unsuccessfully

[Class1.cs]

ArrayList1 arrayList1 = new ArrayList();
arrayList1.add...........
myQueue.Enque(arrayList1);

[myQueue.cs]
internal class myQueue
{
   private static Queue que = Queue.Synchronized(new Queue());

   internal static void Enque(ArrayList list)
   {
         que.Enqueue(list);
   }

    internal static ArrayList Deque()
    {
         return (ArrayList)que.Dequeue();
    }  
}

[Class2.cs]
ArrayList al = myQueue.Deque();
foreach (Object o in al)
{
    Console.WriteLine(o.ToString());
}

NOT returning any data, just count 0

Maybe this is a Windows Service & threading issue?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTW, how you pass the queue object between classes?
Good point...

1. I use "MyQueue myQueue = new MyQueue" ONLY 1 time in entire project.
2. I instanciate ALL classes & threads in very 1st boot-up class (via service1 OnStart()).
2. Unusual that I can grab strings all day long, but cannot return the ArrayList.
Regarding #1, everything in myQueue is STATIC, so you don't need an instance of it.