Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Windows limit to the number Process objects you can create and start?

It seems there are questions close to this, but none I have seen involve the actual .Net Process object. Currently, I am using a Process object to start an external executable and read data from it in C#. This happens once for each collection point that I must monitor data for. However, when I have to monitor 5 or more collection points my process for the fifth collection point is killed before I can collect any data from it. The code used to start the Process object is list below. Any help is appreciated.

    procCollectionMonitor = new Process();
    procCollectionMonitor.StartInfo.FileName = options.CollectionMonitorProcessPath;

    procCollectionMonitor.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(options.CollectionMonitorProcessPath);
    procCollectionMonitor.StartInfo.ErrorDialog = false;

    procCollectionMonitor.StartInfo.UseShellExecute = false;

    procCollectionMonitor.EnableRaisingEvents = true;
    procCollectionMonitor.Exited += spawn_Exited;
    procCollectionMonitor.Start();

This application is a Windows Service, that runs on Windows Server 2008 R2. As I said before, this issue only occurs when 5 or more collection points are started. Instances where 4 or less are needed have no problems.

like image 441
jnich91 Avatar asked Dec 05 '25 13:12

jnich91


2 Answers

Since you are using a Windows Service, there is definitely a limit. The limit can be controlled through Desktop Heap. Check the below answer for more details on this:

How to increase the maximum number of child processes that can be spawned by a windows service -- desktop heap limits

You simply need to do the following:

Go to regEdit, and navigate to the key:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems

Edit the key named "Windows" from:

%SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows SharedSection=1024,20480,768 Windows=On SubSystemType=Windows ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3 ServerDll=sxssrv,4 ProfileControl=Off MaxRequestThreads=16

to:

%SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows SharedSection=1024,20480,2048 Windows=On SubSystemType=Windows ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3 ServerDll=sxssrv,4 ProfileControl=Off MaxRequestThreads=16

Also this is supposed to fix the issue, I believe the optimum solution will be to find a work around to start the process independent from the Window service (which till now I don't know how)

Updated: I found a workaround to solve this issue... you can use the method "CreateProcessAsUser" for more details please check the below link:

https://www.codeproject.com/Articles/35773//Articles/35773/Subverting-Vista-UAC-in-Both-32-and-64-bit-Archite

like image 192
Sufyan Jabr Avatar answered Dec 09 '25 14:12

Sufyan Jabr


There is no practical limit to the number of processes you can start. Starting five should certainly not be a problem. Your use of C# and .NET will not have an impact. The Process class in .NET is just a managed wrapper for the Win32 CreateProcess and ShellExecuteEx APIs. The problem must lie with program that you're launching. You'll need to analyze it to figure out what's going on.

like image 34
Peter Ruderman Avatar answered Dec 09 '25 14:12

Peter Ruderman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!