2012-02-08 75 views
2

我有一個項目類型office 2010 word文檔。Word文檔。關閉和線程中止異常Windows 7

在功能區有一個按鈕,它執行一些邏輯。 這個邏輯的盡頭有這樣一行:

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 

可能是什麼原因?

回答

0

這似乎是AppDomain卸載並將執行從非託管代碼返回到託管代碼的問題。 See MSDN forums其中討論這ThreadAbortExcpetion行爲。可能您只需更新VSTO運行系統。

+0

我有VS 2010 VSTO 4.0。如何檢查我的VSTO運行時版本,如果需要更新它? – shin 2012-02-08 17:26:12

+0

你如何部署加載項?通常這是在安裝過程中完成的。 – SliverNinja 2012-02-08 17:31:22

+0

這不是加載項。這是Word Document 2010項目。在VS中,我看到類似於Microsoft.Office.Tools.Word.v9.0.dll運行時v2.0.50727 – shin 2012-02-08 17:37:14

0

試試這個:

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()); 
     } 
    } 
+0

nope的東西,它不起作用。我們決定不關閉我們的應用程序,而只關閉文檔。用戶必須手動關閉單詞。 – shin 2012-02-20 10:23:15