How To Kill WinWOrd Process In C#
When You open MS Word Document pro-grammatically using 'Microsoft.Office.Interop.Word', you are creating 'winword' process. So after dealing with opened MS Word document pro-grammatically though you close it using 'close' method, the 'winword' process is not terminating, it is still running on your OS. So you have to terminate it in the end of the program otherwise, it creates so many 'winword' processes for each time you open MS Word document and you may face to memory problems later.
You can use below code to kill 'Winword' process.
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("winword"))
{
if (!p.HasExited)
{
p.Kill();
}
}
You can use below code to kill 'Winword' process.
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("winword"))
{
if (!p.HasExited)
{
p.Kill();
}
}
I had good results doing something like this. I like your method too, makes sure it closes.
ReplyDeletewhile (System.Runtime.InteropServices.Marshal.ReleaseComObject(doc) != 0) { }
GC.Collect();
GC.WaitForPendingFinalizers();