If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Question regarding waitforsingleobject

I have doubt regarding waitforsingleobject or alternate function to use in the following scenario.

Example
I am entering Username and password and clicking on OK.The next window may appear in 1 second, 10 second or 120 second.I want to write a program like this.I should give wait time.Condition is this if the next window appears in 1 second the consecutive actions should go on else it should wait till the next window. How to do this. kindly help me.

Re: Question regarding waitforsingleobject

Most likely you don't want to use WaitForSingleObject in the main UI thread (because if you do, it will block the UI and the user won't be able to do anything).

Instead, you most likely want to handle a message and the message handler takes you to the next operation. If you handle a message, then it doesn't matter if it comes in 1, 10, or 30 seconds later (unless it's important to have a timeout error).

Re: Question regarding waitforsingleobject

Elaorating on Arhay's post, you can also make sure your WaitForSingleObject() has a short timeout, in in the timeout case test for state variables being set, that would let you take the next course of action. But as Arjay pointed out, WaitForSingleObject() used in the main thread can cause you all kinds of grief. A better approach might be to set up an ongoing OnTimer() event, and a state machine. This will allow you to still write code to watch and analyze whether various user entries have been properly (or improperly) completed, and then change the state in your state machine to reflect what to do next. Based on your limited explanation of what you are doing, that would be my approach.