0

In a windows service project in c# I create 2 threads to execute 2 jobs. When looking at the process explorer tool I see more than 30 threads created for the process. Debugging through my code I don't see more than 2 threads being created. I'm not sure why I'm seeing so many threads for the process in the process explorer.

The threads are supposed to run every 2 minutes so I call Thread.Sleep(time).

Any ideas why I'm seeing so many threads in my process explorer?

The jist of what I'm seeing is shown below, but instead of 4 threads I'm saying a whole lot more:

Process                 PID     Type    Name
MyService.vshost.exe    1234    Thread  MyService.vshost.exe(1234) 1265
MyService.vshost.exe    1234    Thread  MyService.vshost.exe(1234) 6528
MyService.vshost.exe    1234    Thread  MyService.vshost.exe(1234) 3175
MyService.vshost.exe    1234    Thread  MyService.vshost.exe(1234) 5325

Thanks in advance.

4
  • Why don't you post the output of process explorer so we can see what you are concerned about? Commented Nov 18, 2014 at 2:43
  • @Steve I don't have access to my output at the moment. I can try and post something soon. What concerns me is that I am expecting only 2 threads for the process ID. I'm seeing a lot more threads for the processID. I'm concerned about performance and going through the code I can't seem to find where more threads are being created. Commented Nov 18, 2014 at 2:48
  • 1
    The .Net framework will have its own threads running for GC etc. I just tried running a brand new console project - 12 threads with debugger attached, 4 without. BTW, is this actually anything to do with asp.net? Commented Nov 18, 2014 at 3:29
  • If all your Windows service does is run some job every two minutes, it probably shouldn't be a service at all, but rather a console application that is run as a scheduled task. See Programs are not cats Commented Nov 18, 2014 at 18:02

1 Answer 1

1

VS doesn't show the other threads because the the debugger is attached to the managed code but most of those threads run native code only.

For attaching to the native code, open Attach to Process window, click Select and in the Select Code Type window select Native as well as Managed.

Visual Studio Code Type Window

Now you can see all the threads in the threads window: managed and native.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.