所以我不斷收到「應用程序正忙」RPC_E_SERVERCALL_RETRYLATER錯誤,下面的代碼。值得注意的是,這個確切的代碼在Word 2003和.doc文件中運行良好。升級到2007年後,它不再有效。它獲得部分數的文件是「.docx」,我已經確保使用正確版本的interop。錯誤通常發生在代碼中的隨機位置。MS Word互操作C#RPC_E_SERVERCALL_RETRYLATER錯誤
public int GetSectionsCount(string fileName) {
wrdApp = new Application();
Object file = fileName;
Documents docs = wrdApp.Documents;
wrdDoc = docs.Open(ref file, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing,
ref oMissing,
ref oMissing);
int count = wrdDoc.Sections.Count;
wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
wrdApp.Quit(ref oFalse, ref oMissing, ref oMissing);
Marshal.ReleaseComObject(docs);
Marshal.ReleaseComObject(wrdDoc);
Marshal.ReleaseComObject(wrdApp);
wrdDoc = null;
wrdApp = null;
return count;
}
一個例子堆棧跟蹤:
at Microsoft.Office.Interop.Word.DocumentClass.get_Sections()
at MyApplication.WordMerge.split(String fileToSplit, String whereToSave, String quarterExtension, Form1 pb) in\\Projects\\MyApplication\\WordMerge.cs:line 176
at MyApplication.PMLettersManager.DoSplits() in \\Projects\\PyForms3\\PMLettersManager.cs:line 179
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
的代碼在自己的線程運行,並沒有其他的MS Word自動化代碼同時運行。再次,它升級之前工作正常。
編輯:當我保存文件問題作爲.DOC而不是.DOCX有沒有錯誤和代碼工作正常。
它與Word 2003工作正常 - 這會影響什麼? – jle
線程混合時,問題可能已經存在,但沒有任何表現,現在由於簡單的更改,您正在碰撞競賽狀態。我會嘗試刪除線程以驗證錯誤是否仍然存在。 –
錯誤仍然發生... – jle