i usually do this through an implementation of the WaitQueue ADT,
i'm pasting a sample c# code, you need to convert it to VB.NET
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Threading;
namespace System.Collections.Extra
{
class WaitQueue<CType> : IDisposable
{
Queue<CType> data = new Queue<CType>();
Semaphore sem = new Semaphore(0,1);
Object __datadeq = new Object();
Object __dataenq = new Object();
public CType Dequeue()
{
lock (__datadeq)
{
if(this.data.Count == 0)
sem.WaitOne();
return data.Dequeue();
}
}
public void Enqueue(CType data)
{
lock (__dataenq)
{
this.data.Enqueue(data);
if(this.data.Count==1)
sem.Release();
}
}
public void Dispose()
{
sem.Close();
this.data.Clear();
}
}
}
Enter your message below
Sign in or Join us (it's free).