Questions tagged [waitforsingleobject]

Use this tag for questions about the function WaitForSingleObject() of the Win32 API.

Waits until the specified object is in the signaled state or the time-out interval elapses.

87 questions
15
votes
5 answers

Which is the correct way to wait for a Thread.finalization and keep my application responsive

Actually i am using this code and works ok, but i 'am wondering if is the correct way. while WaitForSingleObject(MyThread.Handle, 0) = WAIT_TIMEOUT do Application.ProcessMessages; ShowMessage('i am done');
Salvador
  • 16,132
  • 33
  • 143
  • 245
13
votes
7 answers

How to wait for a shell process to finish before executing further code in VB6

I have a small VB6 app in which I use the Shell command to execute a program. I am storing the output of the program in a file. I am then reading this file and putting the output on the screen using a msgbox in VB6. This is what my code looks like…
anubhav
  • 643
  • 3
  • 9
  • 19
11
votes
4 answers

SendMessage vs PostMessage + WaitForSingleObject

I was wondering what's the difference between calling SendMessage (which blocks) and calling PostMessage in conjunction with WaitForSingleObject. Thoughts?
Filip Frącz
  • 5,881
  • 11
  • 45
  • 67
10
votes
2 answers

Is there a C++ equivalent of WaitforSingleObject?

I need to rewrite some code that uses the windows WaitforSingleObject function. myEvent = CreateEvent( NULL, FALSE, FALSE, szName ); WaitForSingleObject( myEvent, nMilliseconds ); I need to wait for an event or for a timeout to happen. Is there an…
Harry Boy
  • 4,159
  • 17
  • 71
  • 122
9
votes
3 answers

unelevated program starts an elevated updater, updater should wait for finishing of program

I have 2 apps, program.exe and updater.exe, both written in Delphi5. Program runs without admin-rights (and without manifest), updater has a manifest with "requireAdministrator" because he must be able to write at Program-Folder to update…
8
votes
4 answers

Is it possible to kill WaitForSingleObject(handle, INFINITE)?

I am having problems closing an application that uses WaitForSingleObject() with an INFINITE timout. The full picture is this. I am doing the following to allow my application to handle the device wakeup event: Register the event…
Chris Wallis
  • 1,263
  • 8
  • 20
8
votes
1 answer

Why does WaitForSingleObject(INVALID_HANDLE_VALUE, INFINITE) block?

Why does HANDLE mutexHandle = INVALID_HANDLE_VALUE; WaitForSingleObject(mutexHandle, INFINITE); block? It does not return with an error message. Checking the handle for INVALID_HANDLE would be stupid for a mutex as I would need a mutex for…
7
votes
3 answers

"machine sleep" + WaitForSingleObject + finite timeout

Strange question here -- but: If I use WaitForSingleObject on a mutex with a 20 minute timeout. Then, the machine enters sleep mode (or hibernate) while waiting.... Upon wake 12 hours later -- will my call to WaitForSingleObject time-out? or will…
pweyzen
  • 151
  • 4
4
votes
2 answers

Worker thread termination in MFC

What is the correct way to terminate a worker thread if it is taking too long to complete? I've read several articles claming that TerminateThread should be used with extreme caution, but I can't find any viable alternative. Psudo code: void…
House Sparrow
  • 107
  • 1
  • 2
  • 7
4
votes
2 answers

WaitForSingleObject with thread handle get stuck while running regsvr32.exe

I have thread A that is creating another thread B, than thread A is waiting using WaitForSingleObject to wait until thread B dies. The problem is that even though thread B returns from the thread's "thread_func", thread A does not get signaled!. I…
TCS
  • 5,790
  • 5
  • 54
  • 86
4
votes
2 answers

Why does WaitForSingleObject() after CreateProcess() show the AppStarting cursor?

I've written a simple launcher that looks up the actual program and then executes it. This works fine, but there is one issue: Windows displays the "pointer with hourglass" cursor for about give seconds. This does not happen if I launch the program…
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
3
votes
1 answer

How 'wait' on a thread is actually working in c++

I would like to understand how 'wait' on a thread is actually working ? Is there an endless loop behind the scene (does not sound resonable) ? For example in MSDN/MFC manual page for 'WaitForSingleObject' function it says The WaitForSingleObject…
ClimbingLung
  • 219
  • 2
  • 8
3
votes
0 answers

Windows: WaitForSingleObject crashes when thread returns 0

I am having a strange behavior: WaitForSingleObject seems to crash when I return 0 from my thread, but if I call "ExitThread(0)" then it does not. void waitForThread(DWORD &threadId) { HANDLE hThread = OpenThread(SYNCHRONIZE, …
user1777907
  • 1,355
  • 4
  • 12
  • 28
3
votes
1 answer

Win 8 Metro mode: WaitForSingleObjectEx failed

I'm trying to implement something like Sleep(msec) behavior in metro mode like this void win8_metro_mode_sleep(unsigned long long ms) { HANDLE hEvent; DWORD ret; DWORD err; DWORD msec = ms; print_on_text_box("\nMSEC: "); …
2
votes
1 answer

What are the benefits of using WaitForMultipleObjects instead of WaitForSingleObject in a loop?

I have a vector. I want to wait for all of them to finish. I don't want to copy them over to an array. What are the benefits of doing so anyway and using WaitForMultpleObjects, rather than using WaitForSingleObject in a loop if any? Thanks!
1
2 3 4 5 6