C# Word文档。关闭并线程中止异常Windows 7

C# Word文档。关闭并线程中止异常Windows 7,c#,.net,ms-word,vsto,ms-office,C#,.net,Ms Word,Vsto,Ms Office,我有一个项目类型的office 2010 word文档 在ribbon中有一个按钮,它执行一些逻辑操作。 在该逻辑的末尾,有一行如下所示: Globals.ThisDocument.Application.ActiveDocument.Close(ref dowdSaveChanges, ref oMissing, ref oMissing); 在Windows XP上,一切正常,但当用户尝试在Windows 7上使用此文档时,这行代码会引发异常,如: System.Threading.Thr

我有一个项目类型的office 2010 word文档

在ribbon中有一个按钮,它执行一些逻辑操作。 在该逻辑的末尾,有一行如下所示:

Globals.ThisDocument.Application.ActiveDocument.Close(ref dowdSaveChanges, ref oMissing, ref oMissing);
在Windows XP上,一切正常,但当用户尝试在Windows 7上使用此文档时,这行代码会引发异常,如:

System.Threading.ThreadAbortException: The thread was beeing aborted. 
   w Document35.WorkflowRibbon.Button1Click(Object sender, RibbonControlEventArgs e) w D:\_DEV\WorkflowCS2_WordTemplatest_Office2010\Document35\WorkflowRibbon.cs:wiersz

原因可能是什么?

这似乎是AppDomain卸载并将执行从非托管代码返回到托管代码的问题。其中讨论了此
threadabortexcption
行为。您可能只需要更新VSTO运行时。

这似乎是AppDomain卸载并将执行从非托管代码返回托管代码的问题。其中讨论了此
threadabortexcption
行为。您可能只需要更新VSTO运行时。

尝试以下操作:

    private void Button1Click(object sender, RibbonControlEventArgs e)
    {
        object oMissing = System.Reflection.Missing.Value;
        object dowdSaveChanges = WdSaveOptions.wdDoNotSaveChanges;
        try
        {                
             Globals.ThisDocument.Application.ActiveDocument.Close(ref dowdSaveChanges, ref oMissing, ref oMissing);                
        }
        catch (ThreadAbortException t)
        {
            Globals.ThisDocument.ThisApplication.Quit(ref dowdSaveChanges, ref oMissing, ref oMissing);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }
试试这个:

    private void Button1Click(object sender, RibbonControlEventArgs e)
    {
        object oMissing = System.Reflection.Missing.Value;
        object dowdSaveChanges = WdSaveOptions.wdDoNotSaveChanges;
        try
        {                
             Globals.ThisDocument.Application.ActiveDocument.Close(ref dowdSaveChanges, ref oMissing, ref oMissing);                
        }
        catch (ThreadAbortException t)
        {
            Globals.ThisDocument.ThisApplication.Quit(ref dowdSaveChanges, ref oMissing, ref oMissing);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

我有VS2010和VSTO 4.0。如何检查我的VSTO运行时版本并在需要时进行更新?如何部署外接程序?通常这是在安装过程中完成的。这不是外接程序。这是Word文档2010项目。在VS中,我看到了类似于Microsoft.Office.Tools.Word.v9.0.dll runtime v2.0.50727的东西,我在VS2010中看到了VSTO 4.0。如何检查我的VSTO运行时版本并在需要时进行更新?如何部署外接程序?通常这是在安装过程中完成的。这不是外接程序。这是Word文档2010项目。在VS中,我看到类似于Microsoft.Office.Tools.Word.v9.0.dll runtime v2.0.50727的东西不,它不会工作。我们决定不关闭应用程序,只关闭文档。用户必须手动关闭word。不,它无法工作。我们决定不关闭应用程序,只关闭文档。用户必须手动关闭word。