开发者

Very slow interop with Word in c# application

I use VS2005 and I need to create many .doc files. My computer(Intel c2d6600 with 2gb RAM) can convert with 10 files/minute it is very slow for me. What should I do to improve perfomance?

My code:


oWord = new Word.Application();
oMissing = System.Reflection.Missing.Value;
oDoc = this._oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

...
//Do something
...

//save rtf
object fileName = this.FileRtf;
object fileFormat = Word.WdSaveFormat.wdFormatRTF;
object savechanges = false;
oDoc.SaveAs(ref fileNa开发者_开发技巧me, ref fileFormat, 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);
oWord.Quit(ref savechanges, ref oMissing, ref oMissing);


My psychic debugging powers tell me that you need to optimize the below code:

...
//Do something
...


Try to reduce number of calls to

oWord = new Word.Application(); 
//and 
oWord.Quit(ref savechanges, ref oMissing, ref oMissing); 

In other words call them once and use one instance of Word for multiple files.


First, you should profile your application to find out, where the time is spent.

For is list of profilers, see this SO question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜