nbee
April 27th, 2004, 09:40 AM
I have this function:
bool CVirtualDevice::SynchronizeDevice(HANDLE hEvtHandle, long lTimeOutSeconds)
{
MSG Msg;
bool bRst = true;
// '2004.03.18 Seo, B.S. Add TimeOut.
time_t tBegin;
time_t tCurrent;
//if (hEvtHandle == NULL)
// hEvtHandle = m_hSyncEvent;
if (lTimeOutSeconds >= 0)
tBegin = time(NULL);
while(::WaitForSingleObject(hEvtHandle,0) == WAIT_TIMEOUT)
{
if (lTimeOutSeconds >= 0)
{
tCurrent = time(NULL);
if ((tCurrent-tBegin) >= lTimeOutSeconds)
{
bRst = false;
g_Glob->SSG_LOG(LOG_PSYCHE ,LOG_NORNAL,LOG_TRACE, "TimeOut at SynchronizeDevice()");
break;
}
}
if (::PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
Sleep(1);
}
:: CloseHandle(hEvtHandle);
return bRst;
}
and I have 2 functions:
void doOne()
{
SynchronizeDevice(hEvent1, 5);
}
void doTwo()
{
SynchronizeDevice(hEvent1, 10);
}
and I have 2 buttons on the form button1 will call to doOne, button2 will call to doTwo
What I expect is, after 5 seconds, doOne will finish (timeout) and after 10 seconds doTwo will finish (timeout).
But if I click button1 (doOne) and then click button2 (doTwo) -> doOne will freeze until doTwo finish.
Is there any way to separate those 2 loops???
Regards.
bool CVirtualDevice::SynchronizeDevice(HANDLE hEvtHandle, long lTimeOutSeconds)
{
MSG Msg;
bool bRst = true;
// '2004.03.18 Seo, B.S. Add TimeOut.
time_t tBegin;
time_t tCurrent;
//if (hEvtHandle == NULL)
// hEvtHandle = m_hSyncEvent;
if (lTimeOutSeconds >= 0)
tBegin = time(NULL);
while(::WaitForSingleObject(hEvtHandle,0) == WAIT_TIMEOUT)
{
if (lTimeOutSeconds >= 0)
{
tCurrent = time(NULL);
if ((tCurrent-tBegin) >= lTimeOutSeconds)
{
bRst = false;
g_Glob->SSG_LOG(LOG_PSYCHE ,LOG_NORNAL,LOG_TRACE, "TimeOut at SynchronizeDevice()");
break;
}
}
if (::PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
Sleep(1);
}
:: CloseHandle(hEvtHandle);
return bRst;
}
and I have 2 functions:
void doOne()
{
SynchronizeDevice(hEvent1, 5);
}
void doTwo()
{
SynchronizeDevice(hEvent1, 10);
}
and I have 2 buttons on the form button1 will call to doOne, button2 will call to doTwo
What I expect is, after 5 seconds, doOne will finish (timeout) and after 10 seconds doTwo will finish (timeout).
But if I click button1 (doOne) and then click button2 (doTwo) -> doOne will freeze until doTwo finish.
Is there any way to separate those 2 loops???
Regards.