You are writing a Word operation. One of the operations is to export data tables. The code is okay at the beginning, but when the amount of data is too large to be exported, the error "message filter shows that the application is in use" is reported, which makes me puzzled. Check the code repeatedly to make sure the code is correct. So I went online to find a solution. However, all the information on the Internet is about access denial errors caused by component permission issues. This error occurs occasionally when I operate the Word. Normally, this error is reported only when the data volume is large. So I think it's weird.
If you want to think about it, there is only one kind of problem that may cause this problem, that is, other programs are occupying the process of accessing the Word or Word I operate on. But what is it. After I tried it several times, I understood it. Now let's talk about the root cause of this problem:
The reason is: word spelling check
After I insert a large amount of data into the Word, a large number of spelling errors are detected in the automatic spelling check of the Word. Therefore, a prompt box is displayed, prompting users to have too many spelling errors. In our program, Word is run in the background, so the program does not know that Word plays a dialog box. When the program continues to insert data into the Word, because the Word process is blocked in the Word dialog box, the message filter displays the application in use error.
It is easy to solve the problem after knowing the root cause:
Reference Microsoft. Office. Interop. Word. dll
Word. Application word = new Word. ApplicationClass ();
Word. Document doc = word. Documents. Add (ref missing, ref missing );
Doc. SpellingChecked = false;
Doc. ShowSpellingErrors = fase;
Close the Word spelling check.
Solve the problem OK.