服务器端调用Microsoft.Office.Interop.Word频繁建立ApplicationClass对象比较耗时,实现了一个Word对象池以空间换时间,对象池中的Word对象用过一次后调用Document.Quit(ref ...,ref ..,ref ...)后就放回对象池以备下次使用,但是发现Word对象并没有彻底和文档脱离关联(非要调WordApplication.Quit方法才可以),但是我不想它立即退出而是要放回对象池的,这个问题该怎么解决呢,WordApplication有没有什么重新初始化的方法呀?

解决方案 »

  1.   

    是否WORD进程提高应用程序池的权限,配置标识为本地系统
       Doc.Close(ref NOTsaveChanges, ref originalFormat, ref routeDocument);
                    app.Quit(ref NOTsaveChanges, ref originalFormat, ref routeDocument);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(Doc);
                    app = null;
                    Doc = null;
    System.Diagnostics.Process myproc= new System.Diagnostics.Process();
    foreach (Process thisproc in Process.GetProcessesByName(processName)) {
    if(!thisproc.CloseMainWindow()){
    thisproc.Kill();
    }}
    在重写new