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 859613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:42:09+00:00 2026-05-15T08:42:09+00:00

Let say I have three thread handles HandleList[0] = hThread1; HandleList[1] = hThread2; HandleList[2]

  • 0

Let say I have three thread handles

HandleList[0] = hThread1;
HandleList[1] = hThread2;
HandleList[2] = hThread3;
/*All the above are of type HANDLE*/

Before closing the application, I want the thread to get its task done. So I want to make app wait till thread completes.

So I do,

WaitForMultipleObjects(3, HandleList, TRUE, INFINITE );

By this I’m able to make the thread, complete its task. But control never move to next line after the call to WaitForMultileObjects irrespective of all thread completing its task.

If I use, some seconds instead of INFINITE, it comes to next line after that many secs, irrspective of whether thread completes its task or not.

WaitForMultipleObjects(3, HandleList, TRUE, 10000 );

My problem here is, I’m can’t go for seconds, as I may not be sure whether the threads will complete its task with the given time.

To list my problem in simple words,
I want all my thread to finish the task, before I close my app. How can I achieve it using WaitForMultipleObjects API?

EDIT:
As per MSDN..

dwMilliseconds
[in] Time-out interval, in milliseconds.

  • The function returns if the interval elapses, even if the conditions specified by the bWaitAll parameter are not met.
  • If dwMilliseconds is zero, the function tests the states of the specified objects and returns immediately.
  • If dwMilliseconds is INFINITE, the function’s time-out interval never elapses.
  • 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-15T08:42:09+00:00Added an answer on May 15, 2026 at 8:42 am

    The simple answer is that you cannot achieve this with WaitForMultipleObjects.

    The problem here is that the fault is not with this function, it’s doing exactly what it is supposed to do, it waits for the threads to finish.

    The problem here is that one or more of the threads never finish.

    And that is the problem you need to solve. Why isn’t the threads finishing?

    Are they deadlocked? Are they running in a loop they aren’t breaking out of?

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

Sidebar

Related Questions

Let's say I have a situation in Silverlight where there is a background thread
Let's say you have three tables named Item, Event, and Seat, constructed as such:
Let's say I have the following three strings: (section1){stuff could be any character, i
Let's say I have the following xml: <one> <two> <three> <three> foo </three> <four
I've got a question regarding multiple-thread method invocation in Java. Let's say we have
Let's say I have a type of lookup table which I can build for
Let's say I have a manual event handle h (created with CreateEvent , manual).
Let's say I have a multithreaded C++ program that handles requests in the form
iSo let's say I have three different arrays of objects, and I want to
Let's say that in enclosing scope, I have some variables that each thread in

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.