Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Queue consumer
public class PollingService
{
private Thread _workerThread;
private AutoResetEvent _finished;
private const int _timeout = 60*1000;
private readonly Queue<Work> _queue = new Queue<Work>();
public void StartPolling()
{
_workerThread = new Thread(Poll);
_finished = new AutoResetEvent(false);
_workerThread.Start();
}
private void Poll()
{
while (!_finished.WaitOne(_timeout) || _queue.Any())
{
var work = _queue.Pop()
work.Execute()
//do the task
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment