Word文档.关闭并线程中止异常Windows 7
本文关键字:异常 Windows 线程 文档 Word | 更新日期: 2023-09-27 18:23:51
我有一个项目类型的office 2010 word文档。
在功能区中有一个按钮,它执行一些逻辑操作。在这个逻辑的末尾有一行类似于:
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卸载并将执行从非托管代码返回到托管代码的问题。请参阅讨论此ThreadAbortExcpetion
行为的MSDN论坛。您可能只需要更新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());
}
}