private static void SingleAppComThread_DoWork() { while (!exitComThread) { // check for a signal. if (threadComEvent.WaitOne()) { threadComEvent.Reset(); // The user tried to start another instance. We can't allow that, // so bring the other instance back into view and enable that one. // That form is created in another thread, so we need some thread sync magic. if (!exitComThread) { ds4form?.Invoke(new SetFormVisableDelegate(ThreadFormVisable), ds4form); } } } }