public void Stop()
{
lock (syncRoot)
{
if (workThread == null)
return;
// signal thread to die
if (cts != null)
cts.Cancel();
// wait for thread to die
workThread.Join();
// clean up state
workThread = null;
cts = null;
}
}