How to check if the thread is finished?

winanjaya 146 Reputation points
2022-11-23T03:49:12.813+00:00

Hi All,

I have 2 threads below, How to check if they finished the job?

       new Thread(new ParameterizedThreadStart(Models.Cron.Job1)).Start(new object[] { tokensPid, token, scheduleType, tokenInfo, cronsPid1 });  
        
       new Thread(new ParameterizedThreadStart(Models.Cron.Job2)).Start(new object[] { tokensPid, token, cronsPid2, tokenInfo });  
Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Dillon Silzer 57,831 Reputation points Volunteer Moderator
    2022-11-23T05:37:59.443+00:00
    0 comments No comments

  2. Anonymous
    2022-11-23T07:40:57.6+00:00

    Hi @winanjaya ,

    You can check the Thread.ThreadState Property, then, it will return one of the ThreadState values indicating the state of the current thread.

    Refer to the following sample code:

    263382-image.png


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.