How do you get list of running threads in C#?

后端 未结 5 1070
眼角桃花
眼角桃花 2021-02-01 11:12

I create dynamic threads in C# and I need to get the status of those running threads.

List[] list;
list = dbConnect.Select();

for (int i = 0; i &l         


        
5条回答
  •  天涯浪人
    2021-02-01 11:26

    Use Process.Threads:

    var currentProcess = Process.GetCurrentProcess();
    var threads = currentProcess.Threads;
    

    Note: any threads owned by the current process will show up here, including those not explicitly created by you.

    If you only want the threads that you created, well, why don't you just keep track of them when you create them?

提交回复
热议问题