Click here to Skip to main content
15,887,596 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Windows Services Cannot Create More than a Certain Number of Processes

Rate me:
Please Sign up or sign in to vote.
2.33/5 (3 votes)
20 Jan 2016CPOL2 min read 6.1K   1   2   1
Windows Services cannot create more than a certain number of processes, whereas Console Applications seem not to have a limit.

It seems, that Windows Services cannot create more than a certain number of processes. In the attached Visual Studio Solution, a Windows Service starts 100 processes. However, after a certain number of processes created, the subsequent processes fail to start. Using the same code in a Console Application, all processes start successfully. The number of failed processes seems to vary between computers. On a computer with Windows 7, there were 15 (out of 100) failed processes, on a computer with Windows Server 2012 there were 4 (out of 100) failed processes. Therefore, the following questions arise:

  1. Is there a configuration that limits the number of processes created by a Windows Service?
  2. If this is a bug, is there a patch for this?
  3. Which is the recommended way to start processes from a Windows Service?

Steps to reproduce the problem are listed below:

  1. Unzip WinServiceCreateProcesses.zip.
  2. Open the created folder, WinServiceCreateProcesses.
  3. Open WinServiceCreateProcesses.sln. The solution contains two projects: WindowsService1 and ConsoleApplication1.
  4. WindowsService1 is the Windows Service that starts 100 processes of ConsoleApplication1. Compile the solution.
  5. Double click on InstallService.bat. This will install the Windows Service WindowsService1.
    Depending on the user’s privileges, this might have to be run as administrator.
  6. Start/Run/Services.msc to start the Services Console.
  7. Select WindowsService1, right-click, select Start to start the Windows Service.
  8. Start/Run/Eventvwr.msc to start the Event Viewer.
  9. Select Windows Logs/Application, right-click, select Refresh.
  10. The latest log entry should be similar to this:
    StartService nr alive=85, nr dead=15, 
    dead ids=86,87,88,89,90,91,92,93,94,95,96,97,98,99,100

    That means, that 100 processes were started, but 15 seem not to be alive.
    This may be verified, by counting the number of ConsoleApplication1 processes in the Task Manager.

  11. In the Services Console, select WindowsService1, right-click, select Stop to stop the Windows Service.
    This will kill all the started ConsoleApplication1 processes. If something went wrong, these may be killed by double-clicking on KillProcesses.bat. Depending on the user’s privileges, this might have to be run as administrator.
  12. In Visual Studio/Solution Explorer, right-click on WindowsService1 and select Properties.
  13. Change the Application Type to Console Application and change the Startup object to Module1. This way,
    WindowsService1 is transformed to a Console Application.
  14. Recompile the solution.
  15. Double-click on bin/WindowsService1.exe.
    This will start WindowsService1.exe as a Console Application, which in turn will open 100 Console windows.
  16. In the Event Viewer/Windows Logs/Application, right-click, select Refresh.
  17. The latest log entry should be similar to this:
    StartService nr alive=100, nr dead=0, dead ids=

    That means, that 100 processes were started, and all 100 seem to be alive.
    This may be verified, by counting the number of ConsoleApplication1 processes in the Task Manager.

  18. Type the Enter key in the first Console Window (which is the WindowsService1.exe window) to stop the
    Console Application WindowsService1.exe. This will kill all the started ConsoleApplication1 processes.
  19. Double click on UnInstallService.bat. This will uninstall the Windows Service WindowsService1.

History

  • 20th January, 2016: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Unisystems
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThis happened to me a while back Pin
Paul Tait20-Jan-16 19:14
Paul Tait20-Jan-16 19:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.