Home » excel » c# – Maximum number of excel processes?

c# – Maximum number of excel processes?

Posted by: admin April 23, 2020 Leave a comment

Questions:

If I do (for example)

 for (int i=0;i<22;i++)
 {
     var app = new Excel.Application();
 }

then 22 excel processes are created.

However, if I do

 for (int i=0;i<25;i++)
 {
     var app = new Excel.Application();
 }

It creates 22 excel processes, but then most of them dissapear and only a few are left.

Is there a limit of 22 or something? Can this be increased?

Thanks!

EDIT: with following code it doesn’t occur:

 var apps = new List<Application>();
 for (int i=0;i<25;i++)
 {
      apps.Add(new Application());
 }
How to&Answers:

Garbage collection kicked in… with following code, it works:

 var apps = new List<Application>();
 for (int i=0;i<25;i++)
 {
      apps.Add(new Application());
 }

Answer:

I remember an article by Raymond Chen. Something about if you load too many of the same process for your specific machine, the OS cuts you off. It’s different for every machine (as it’s based on the performance of your machine).

However, I can’t see 25 as being a limit. That seems slightly too small, even for older machines. Are any of your files referencing data from the same files causing some of them to close prematurely because another instance of Excel is locking the file?

I’d need more information to find out what is actually going on.