public void WaitForStop() { if (thread != null) { // wait for thread stop thread.Join(); thread = null; } }