Do While not glQuit If WaitForSingleObject(m.lnHandle,500) == WAIT_OBJECT_0 * do something Endif DoEvents EnddoSet glQuit in the ON SHUTDOWN procedure. If your application needs to accept input, you should rather use MsgWaitForMultipleObjects(). Be aware that DOEVENTS isn't available in DLL servers.