Sunday, July 5, 2020

How to KILL running excel processes in C#

While working with Excel files, you enconter multiple instance of excel processes are running in background(can be seen in Task Manger Processes). This will cause issues when trying to create and manupulate excel files in another program. Therefore, before working(reading/writing) with any excel objects, as a practice clean up the existing/running excel instances.
var processes = from p in Process.GetProcessesByName("EXCEL") select p;
            
foreach (var process in processes)
{
	process.Kill();
}

No comments:

Post a Comment