Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/plugins/servicebackends/windows/windowsservicebackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Q_LOGGING_CATEGORY(logBackend, "qt.service.plugin.windows.backend")
QPointer<WindowsServiceBackend> WindowsServiceBackend::_backendInstance;

static QString xPath;
static std::atomic<bool> isApplicationReady{false};

WindowsServiceBackend::WindowsServiceBackend(Service *service) :
ServiceBackend{service}
Expand Down Expand Up @@ -130,6 +131,7 @@ int WindowsServiceBackend::runService(int &argc, char **argv, int flags)

//execute the app
qCDebug(logBackend) << "running application";
isApplicationReady = true;
_status.dwServiceSpecificExitCode = app.exec();
if(_status.dwServiceSpecificExitCode != EXIT_SUCCESS)
_status.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR;
Expand Down Expand Up @@ -230,10 +232,14 @@ void WindowsServiceBackend::serviceMain(DWORD dwArgc, wchar_t **lpszArgv)
lock.unlock();

// wait for the mainthread to finish startup, then register the service handler
lock.relock();
qCDebug(logBackend) << "wait for main thread to finish startup";
_backendInstance->_startCondition.wait(&_backendInstance->_svcLock);
lock.unlock();
// we wait until variable isApplicationReady become true
while (!isApplicationReady)
{
lock.relock();
qCDebug(logBackend) << "wait for main thread to finish startup";
_backendInstance->_startCondition.wait(&_backendInstance->_svcLock, 5000);
lock.unlock();
}

// handle the start event
qCDebug(logBackend) << "handle service start event";
Expand Down