void Work() { while (true) { TCADSTask task = null; lock (_locker) if (_tasks.Count > 0) { task = _tasks.Dequeue(); if (task == null) { return; } } if (task != null) { task.Work(); // Perform TcAdsClient action (read/write) task = null; // Set task to null (clean-up?) //Thread.Sleep(1); // simulate work... } else { _wh.WaitOne(); // No more tasks - wait for a signal } } }
public void EnqueueTask(TCADSTask task) { lock (_locker) _tasks.Enqueue(task); _wh.Set(); }