waitforsingleobject

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

早过忘川 提交于 2019-12-21 12:08:49
问题 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 with: CeRunAppAtEvent("\\\\.\\Notifications\\NamedEvents\\WakeupEvent", NOTIFICATION_EVENT_WAKEUP); Start a new thread to wait on: Thread waitForWakeThread = new Thread(new ThreadStart(WaitForWakeup)); waitForWakeThread.Start(); Then do the following in the target

SendMessage vs PostMessage + WaitForSingleObject

我的梦境 提交于 2019-12-21 09:16:09
问题 I was wondering what's the difference between calling SendMessage (which blocks) and calling PostMessage in conjunction with WaitForSingleObject. Thoughts? 回答1: SendMessage() may be denied, if you call it from within the context of a COM call, where the COM object lives in an STA (calls are dispatched through the message pump). PostMessage() is not restricted to adhere to COM apartment rules. Also, PostMessage() puts the message on the end of the window's message queue. SendMessage() bypasses

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

 ̄綄美尐妖づ 提交于 2019-12-20 18:27:53
问题 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'); 回答1: Calling Application.ProcessMessages is generally considered a code smell. Let your main thread idle if it's got nothing to do. If you ran a company and needed one of your workers to run to the store and grab some much-needed supplies, would you then pace by the door until he got back,

WaitForSingleObject doesn't wait the end of the process [duplicate]

五迷三道 提交于 2019-12-20 07:47:09
问题 This question already has answers here : Why those two different behaviors with WaitForSingleObject function in CPP (2 answers) Closed last year . I would like to wait the end of the process execution (calc.exe) but it doesn't work. My program finishes fast/now while my process(calc.exe) continue to run (I don't stopped it). and WaitForSingleObject returns immediatly WAIT_OBJECT_0. ps: I disabled my software anti-virus (AVIRA) int main(int argc, char** arv) { STARTUPINFO si; PROCESS

Waitforsingleobject works when trying to open Notepad++ but returns immediately with Firefox

心不动则不痛 提交于 2019-12-11 18:06:20
问题 I have the following code that opens an application using CreateProcess and waits for it for a few seconds and then closes it if its not been closed. The same code works OK on notepad++ for example, but not when I try to open Firefox.exe BOOL CALLBACK SendWMCloseMsg(HWND hwnd, LPARAM lParam) { //never gets called when opening Firefox.exe DWORD dwProcessId = 0; GetWindowThreadProcessId(hwnd, &dwProcessId); if (dwProcessId == lParam) SendMessageTimeout(hwnd, WM_CLOSE, 0, 0, SMTO_ABORTIFHUNG,

Time passed till WaitForSingleObject returned

二次信任 提交于 2019-12-11 08:18:24
问题 Is there a way to know how much time passed from when I called WaitForSingleObject function untill it returned? or that the only way of knowing is by using some kind of a timer? 回答1: Just store current time before calling WaitForSingleObject() . Then compare to time when it returns. From http://msdn.microsoft.com/en-us/library/windows/desktop/ms725473(v=vs.85).aspx - select a function to retrieve time. 回答2: You will need to use a timer if you need to track that. The other alternative

In WaitForSingleObject, is timeout=INFINITE the same as timeout=-1?

混江龙づ霸主 提交于 2019-12-11 01:19:38
问题 I'm working with some Visual Basic for Applications (VB 6.3) code written by someone else, and they've written: WaitForSingleObject SEI.hProcess, -1 The process this appears in is supposed to return some data in a text box; sometimes it fails to return anything, and I think it's because of this, possibly because it's its timing out. Is that code the same as: WaitForSingleObject SEI.hProcess, INFINITE ??? Thanks for your help. 回答1: The timeout for WaitForSingleObject is actually a DWORD ,

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

本秂侑毒 提交于 2019-12-04 04:21:54
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 with: CeRunAppAtEvent("\\\\.\\Notifications\\NamedEvents\\WakeupEvent", NOTIFICATION_EVENT_WAKEUP); Start a new thread to wait on: Thread waitForWakeThread = new Thread(new ThreadStart(WaitForWakeup)); waitForWakeThread.Start(); Then do the following in the target method: private void WaitForWakeup() { IntPtr handle = CreateEvent(IntPtr.Zero, 0, 0, "WakeupEvent");

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

怎甘沉沦 提交于 2019-12-03 05:35:24
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'); Mason Wheeler Calling Application.ProcessMessages is generally considered a code smell. Let your main thread idle if it's got nothing to do. If you ran a company and needed one of your workers to run to the store and grab some much-needed supplies, would you then pace by the door until he got back, or would you prefer to sit in your office and rest and wait for him, and find out that the

WaitForSingleObject doesn't wait the end of the process [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-02 13:12:59
This question already has an answer here: Why those two different behaviors with WaitForSingleObject function in CPP 2 answers I would like to wait the end of the process execution (calc.exe) but it doesn't work. My program finishes fast/now while my process(calc.exe) continue to run (I don't stopped it). and WaitForSingleObject returns immediatly WAIT_OBJECT_0. ps: I disabled my software anti-virus (AVIRA) int main(int argc, char** arv) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); const char * calcPrgm = "C:\\\\Windows