Home » U++ Library support » U++ MT-multithreading and servers » Problem breaking loop (with close button) in main thread
Re: Problem breaking loop (with close button) in main thread [message #59036 is a reply to message #59034] |
Tue, 18 October 2022 20:09   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
On a second thought, your program needs the hMutex be acquired to continue its work. Then ProcessEvent() should be the way to go. Problem is, why is that ProcessEvent() failed you?
Can you try something like the following
DWORD GuiAcquireMutex(HANDLE hMutex, DWORD dwTimeout)
{
if(hMutex == INVALID_HANDLE_VALUE)
return ERROR_INVALID_HANDLE;
DWORD dwLastError = -1;
while ( !g_bQuit && dwLastError != 0 )
{
dwLastError = 0; // Success
switch( WaitForSingleObject(hMutex, dwShortTimeout ) )
{
case WAIT_FAILED:
Do_Set_LastError_Accordingly();
break;
case WAIT_TIMEOUT:
dwLastError = ERROR_COUNTER_TIMEOUT;
break;
}
// consider measure how long it takes ProcessEvents to finish,
// if very quick, consider add a Sleep(500) or something like that
// to avoid keeping CPU busy for nothing.
topwin.ProcessEvents();
if(TooSoon() )
{
Sleep (500);
}
}
SetLastError (dwLastError) ;
return dwLastError;
}
topwin is your TopWindow(or its derivative) object.
I am feeling your original code didnot prepare for the case when the WaitForSingleObject call actually succeeds. I might be wrong though. Above pseudo code will need to be tuned to reflect your true intention.
[Updated on: Tue, 18 October 2022 20:34] Report message to a moderator
|
|
|
 |
|
Problem breaking loop (with close button) in main thread
By: awksed on Tue, 18 October 2022 17:19
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Tue, 18 October 2022 19:15
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Tue, 18 October 2022 20:09
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: awksed on Wed, 19 October 2022 01:11
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Wed, 19 October 2022 02:21
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Wed, 19 October 2022 02:42
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: awksed on Wed, 19 October 2022 20:56
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Thu, 20 October 2022 01:04
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Oblivion on Thu, 20 October 2022 20:10
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Thu, 20 October 2022 21:49
|
Goto Forum:
Current Time: Sun May 11 20:44:45 CEST 2025
Total time taken to generate the page: 0.03037 seconds
|