+ // We must wait for the ticker thread to terminate, since if we
+ // are in a DLL that is about to be unloaded, the ticker thread
+ // cannot be allowed to return to a missing DLL.
+
+ if (hStopEvent != INVALID_HANDLE_VALUE &&
+ tickThread != INVALID_HANDLE_VALUE) {
+ DWORD exitCode;
+ SetEvent(hStopEvent);
+ while (1) {
+ WaitForSingleObject(tickThread, 20);
+ if (!GetExitCodeThread(tickThread, &exitCode)) {
+ return 1;
+ }
+ if (exitCode != STILL_ACTIVE) {
+ tickThread = INVALID_HANDLE_VALUE;
+ return 0;
+ }
+ TerminateThread(tickThread, 0);
+ }
+ }
+ return 0;