[host] detect switch user event and wait instead of terminating

Fixes #22
This commit is contained in:
Geoffrey McRae 2017-12-17 04:50:04 +11:00
parent bf85358715
commit 9d8f3a79b0
2 changed files with 9 additions and 0 deletions

View File

@ -46,6 +46,7 @@ Service::Service() :
m_cursorData(NULL), m_cursorData(NULL),
m_shapePending(false) m_shapePending(false)
{ {
m_consoleSessionID = WTSGetActiveConsoleSessionId();
m_ivshmem = IVSHMEM::Get(); m_ivshmem = IVSHMEM::Get();
} }
@ -233,6 +234,13 @@ bool Service::Process()
case GRAB_STATUS_REINIT: case GRAB_STATUS_REINIT:
DEBUG_INFO("ReInitialize Requested"); DEBUG_INFO("ReInitialize Requested");
if(WTSGetActiveConsoleSessionId() != m_consoleSessionID)
{
DEBUG_INFO("User switch detected, waiting to regain control");
while (WTSGetActiveConsoleSessionId() != m_consoleSessionID)
Sleep(100);
}
if (!m_capture->ReInitialize() || !InitPointers()) if (!m_capture->ReInitialize() || !InitPointers())
{ {
DEBUG_ERROR("ReInitialize Failed"); DEBUG_ERROR("ReInitialize Failed");

View File

@ -49,6 +49,7 @@ private:
~Service(); ~Service();
bool m_initialized; bool m_initialized;
DWORD m_consoleSessionID;
uint8_t * m_memory; uint8_t * m_memory;
IVSHMEM * m_ivshmem; IVSHMEM * m_ivshmem;
HANDLE m_timer; HANDLE m_timer;