private void StopThread(ref IManagedThread thread)
 {
     thread?.Stop();
     thread = null;
 }