AutoResetEvent autoEvent = new AutoResetEvent(true);
public void DowlLoadIds()
{
bool f = autoEvent.Set();
for (int i = 0; i < 30; i++)
{
//System.Threading.Thread t = new Thread(delegate() { DownIdCallBack(autoEvent); });
//t.Start();
TimerCallback timerDelegate = new TimerCallback(DownIdCallBack);
System.Threading.Timer t = new System.Threading.Timer(timerDelegate, autoEvent, 0, 200);
}
}
int i = 0;
private void DownIdCallBack(object o)
{
var autoEvent = (AutoResetEvent)o;
autoEvent.WaitOne();
//System.Threading.Interlocked.Increment(ref i);
i++;
if (i > 20)
{
i = 0;
autoEvent.Reset();
//autoEvent.WaitOne();
return;
}
//Trace.WriteLine(System.DateTime.Now.ToString());
Trace.WriteLine(i.ToString());
autoEvent.Set();
}