Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4620864
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:37:05+00:00 2026-05-22T02:37:05+00:00

I am having problems closing an application that uses WaitForSingleObject() with an INFINITE timout.

  • 0

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");
    while (true)
    {
        WaitForSingleObject(handle, INFINITE);
        MessageBox.Show("Wakey wakey");
    }
}

This all works fine until I try to close the application when, predictably, WaitForSingleObject continues to wait and does not allow the app to close properly. We only allow one instance of our app to run at a time and we check for this on startup. It appears to continue running until the device is soft reset.

Is there a way to kill the handle that WaitForSingleObject is waiting for, to force it to return?

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:37:06+00:00Added an answer on May 22, 2026 at 2:37 am

    Use WaitForMultipleObjects instead, and pass 2 handles. The existing one, and one for an event called something like ‘exit’. During app shutdown, SetEvent on the exit event, and the WaitForMultipleObjects will return and you can get it to exit the thread gracefully.

    You need to switch on the return value of WaitForMultipleObjects to do the appropriate behaviour depending on which one of the handles was triggered.

    Possibly, also, you can set the thread to be a background thread. This will prevent it from stopping your application from shutting down when the main thread terminates.

    See:

    http://msdn.microsoft.com/en-us/library/system.threading.thread.isbackground.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having the following error when closing a form in an application See the
im having problems starting a codeigniter project, the problem is that when i do
I'm having problems using textures that are larger than the OpenGL window or the
I'm having a problem with an application that seems to cancel the shutdown or
I am having a problems with the dismissViewControllerAnimated method not closing down the view.
I'm having troubles getting this to work. Basically I have a python program that
I'm having problems getting an application I wrote for Windows Mobile 6.0 to run
I'm really having trouble closing my console application with FreeGLUT. I would like to
I'm working with VB.net. I’m having problems while I connect my application to my
This is a WPF/C# application and I'm having more of a design problem than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.