Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#应用程序中与Word的互操作非常慢_C#_Rtf - Fatal编程技术网

c#应用程序中与Word的互操作非常慢

c#应用程序中与Word的互操作非常慢,c#,rtf,C#,Rtf,我使用VS2005,需要创建许多.doc文件。 我的电脑(带有2gb内存的英特尔c2d6600)每分钟可以转换10个文件,速度非常慢。 我应该做些什么来提高绩效 我的代码: oWord = new Word.Application(); oMissing = System.Reflection.Missing.Value; oDoc = this._oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissin

我使用VS2005,需要创建许多.doc文件。 我的电脑(带有2gb内存的英特尔c2d6600)每分钟可以转换10个文件,速度非常慢。 我应该做些什么来提高绩效

我的代码:


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

我的心灵调试能力告诉我,你需要优化以下代码:

...
//Do something
...

尽量减少打电话到的次数

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

换言之,只需调用一次,就可以将Word的一个实例用于多个文件。

首先,您应该分析您的应用程序,找出时间花在哪里


有关探查器的列表,请参见此。

Word.paragration oPara。。。;oPara.Range.InsertParagraphAfter()的工作速度很慢,但我在每个文档中都有许多这样的操作:(