locked
how to check all the thread have been run finished. RRS feed

  • Question

  • I have read the following article and I have a doubt, how to judge all the thread have bee finished?

    https://www.codeproject.com/Articles/14931/Asynchronous-Method-Invocation

    Saturday, May 20, 2017 1:47 PM

Answers

  • In that article, he shows you how to use a Callback when the thread is finished. All you would have to do to know when *all* the threads are finished is to keep track of the threads when they are created by adding the ThreadID to a List<int> and removing that ThreadID from the List in the Callback. When the List is empty, all the Threads have been completed.

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Marked as answer by Oscar_Wu Saturday, May 20, 2017 4:15 PM
    Saturday, May 20, 2017 3:56 PM
  • That article is quite archaic. There are other easier ways to manage tasks using the Task Parallel Library. This Documentation could shed some light.

    PS: Kindly close threads by marking answers where appropriate. Thank you.

    • Marked as answer by Oscar_Wu Sunday, May 21, 2017 2:01 PM
    Saturday, May 20, 2017 4:37 PM

All replies

  • I have read the following article and I have a doubt, how to judge all the thread have bee finished?

    https://www.codeproject.com/Articles/14931/Asynchronous-Method-Invocation

    • Merged by Stanly Fan Tuesday, May 30, 2017 7:57 AM the same case
    Saturday, May 20, 2017 1:46 PM
  • In that article, he shows you how to use a Callback when the thread is finished. All you would have to do to know when *all* the threads are finished is to keep track of the threads when they are created by adding the ThreadID to a List<int> and removing that ThreadID from the List in the Callback. When the List is empty, all the Threads have been completed.

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Marked as answer by Oscar_Wu Saturday, May 20, 2017 4:15 PM
    Saturday, May 20, 2017 3:56 PM
  • Yes, Thank you, you are right, I could use list with thread ID to judge whether this thread pool been run finished.
    Saturday, May 20, 2017 4:16 PM
  • That article is quite archaic. There are other easier ways to manage tasks using the Task Parallel Library. This Documentation could shed some light.

    PS: Kindly close threads by marking answers where appropriate. Thank you.

    • Marked as answer by Oscar_Wu Sunday, May 21, 2017 2:01 PM
    Saturday, May 20, 2017 4:37 PM
  • You're welcome! Glad I could help!  =0)

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Saturday, May 20, 2017 4:37 PM
  • Hi qing,

    Sorry for my late reply.

    You can use the Thread.IsAlive property to determine whether the thread has ended.

    And from the document you have provided, I find it is more related with asynchronous method, it shows how to use a Callback when the thread is finished, and in that article, all threads are finished is to keep track of the threads when they are created by adding the ThreadID to a List<int> and removing that ThreadID from the List in the Callback.

    When the List is empty, all the Threads have been finished.

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 22, 2017 5:39 AM