CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 4 of 4

Thread: Question regarding waitforsingleobject

  1. #1
    Join Date
    Jun 2012

    Question Question regarding waitforsingleobject

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

    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.
    Last edited by haroonrulz; January 29th, 2014 at 06:45 AM.

  2. #2
    Join Date
    May 2005

    Re: Question regarding waitforsingleobject

    Your request is not clear please elaborate.
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order


  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004

    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).

  4. #4
    Join Date
    Feb 2014

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)