Suddenly calling:
((Microsoft.Office.Interop.Word._Application)word).Quit(SaveChanges: Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges, OriginalFormat: Type.Missing);
takes forever (30-60 seconds), instead of max 3 secs. It doesn't happen when I have used it to create pdf, but when I create docx. I haven't tried all the different options...
It could have something to do with a new version of Windows recently. I had that suspecion strentghed when I saw some guy had updated an old post less than 2 months ago regarding word interop: LINK See: "Edit on 2019-09-29" I have not tried any of that stuff they write about in there. Mostly because I don't understand it and it has not been neccessary before.
For me, the problem is on 2 windows 10 machines. My desktop has been updated to 1903 a week ago, so it could be that. It still works fine on my windows server running word 2016. My desktop runs word 365, but so does my friend's surface pro 3 and he doesn't have the problem. I don't know if he has updated his windows10 rececently.
Interestingly I had the same problem when I opened word just normally with an empty document and then closed it again. The windows closed, but the task manager word process took a long time to close, so that ofc made me suspecious. I then tried to play with the word settings and when I turned off "Show the Start sceen when this application starts", it started to close down the process immediatly. Ofc I then though: "GREAT, problem solved", but no. Still same problem when use interop. I tried to simulate the turn off of "show the start screen" by adding the following line: word.ShowStartupDialog = false; That just throw an expection, telling me that the ShowStartupDialog is not available when there is no window open. It could be because I run word in non-visible mode.
I ended up solving the problem by putting the quit code in a thread like this, at the end:
System.Threading.Thread t = new System.Threading.Thread(() =>
{
((Microsoft.Office.Interop.Word._Application)word).Quit(SaveChanges:
Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges, OriginalFormat: Type.Missing);
});
t.IsBackground = true;
t.Start();
Then I can continue working in the program and even call the same function again creating another document. It will then start another process while the old one is still closing down. I just tried having 3 closing at the same time, which is enough for my use. Also it takes up quite a lot of cpu 25+% per instance! My computer is not suuuuper new, but it is able to run CS GO just fine, so I really think that should be more than enough machine power :).
Please help be find the actual reason for this and a solution, so I can go back to my original code, which has worked for 4 years.