ProcessManager throws Not enough memory resources are available to process this command

babu

New member
Joined
Jun 16, 2020
Messages
3
Programming Experience
1-3
Team,

NtProcessManager, ProcessManager throws below errors
Not enough memory resources are available to process this command
Exception of type System.OutOfMemoryException was thrown.

And came to know it was thrown from ProcessManager. System.Diagnostics.Process.cs. Please let me know why I am getting error, and how to optimize the code

Get Process having Window:
                IEnumerable<Process> processes = Process.GetProcesses()
                          .Where(p => (long)p.MainWindowHandle != 0
                                    && p.MainWindowTitle.Length > 0
                                    && (p.StartInfo.WindowStyle == ProcessWindowStyle.Maximized
                                            || p.StartInfo.WindowStyle == ProcessWindowStyle.Normal)
                                     );
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,451
Location
Sydney, Australia
Programming Experience
10+
Whenever you have a complex operation like that that fails, the way to diagnose it is to break it down into parts and see which part it fails on. That's what you need to do. I suspect that it has to do with the fact that you're trying to examine the StartInfo of processes that you didn't start. That can't do anything useful and, it may fail outright. The StartIfo property of a Process object is only relevant if you created that Process yourself by starting a process. You can't get the that information from running processes.
 

Similar threads

Top Bottom