Roman N
Roman N

Reputation: 5110

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 fileName, 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);

Upvotes: 0

Views: 1648

Answers (3)

VVS
VVS

Reputation: 19602

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

For is list of profilers, see this SO question.

Upvotes: 1

Tony Kh
Tony Kh

Reputation: 1572

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.

Upvotes: 2

ta.speot.is
ta.speot.is

Reputation: 27214

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

...
//Do something
...

Upvotes: 4

Related Questions