From 10d9678b3decf15d52c11bf562846470782e24b9 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 11 Aug 2020 12:47:50 +1000 Subject: [PATCH] [host] Windows: improved service restart detection --- host/platform/Windows/src/service.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/host/platform/Windows/src/service.c b/host/platform/Windows/src/service.c index a52f8c73..aaed567c 100644 --- a/host/platform/Windows/src/service.c +++ b/host/platform/Windows/src/service.c @@ -496,23 +496,24 @@ VOID WINAPI SvcMain(DWORD dwArgc, LPTSTR *lpszArgv) } setupLogging(); - HANDLE m = CreateMutex(NULL, FALSE, INSTANCE_MUTEX_NAME); ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0); while(1) { /* check if the app is running by trying to take the lock */ bool running = true; + HANDLE m = CreateMutex(NULL, FALSE, INSTANCE_MUTEX_NAME); if (WaitForSingleObject(m, 0) == WAIT_OBJECT_0) { running = false; ReleaseMutex(m); } + CloseHandle(m); if (!running && GetInteractiveSessionID() != 0) Launch(); - if (WaitForSingleObject(ghSvcStopEvent, 100) == WAIT_OBJECT_0) + if (WaitForSingleObject(ghSvcStopEvent, 1000) == WAIT_OBJECT_0) break; }