背景0x3abe010'断开了。从当前上下文释放接口(context 0x3abdea0)

时间:2015-01-03 08:48:40

标签: c# ms-word

我在C#中开发一个应用程序,它在一个选项卡控件中包含一个Office Word组件(在我的例子中是EDrawOfficeViewer)。打开的每个选项卡都将包含一个新的单词组件。因此,当我尝试通过for loop打开10个以上的标签时,会抛出此错误而不显示导致该错误的行。

Context 0x3abe010' is disconnected. Releasing the interfaces from the current
context (context 0x3abdea0).This may cause corruption or data loss. 
To avoid this problem, please ensure that all contexts/apartments stay 
alive until the applicationis completely done with the RuntimeCallableWrapper
that represent COM components that liveinside them.

这是将在for loop中运行以打开我的话语的代码:

_axEdOffice = new AxEDOffice();
SuperTabControlPanel panel = new SuperTabControlPanel();
SuperTabItem tabItem = new SuperTabItem
      {
         Text = dr["IDFish"].ToString(),
         Tag = dr["IDMiddleCategory"],
         AttachedControl = panel
      };
var item = stcWordTab.CreateTab(tabItem, panel, stcWordTab.Tabs.Count);

try
{
    panel.Controls.Add(_axEdOffice);
}
catch
{
     dr.Close();
     dr.Dispose();
     panel.Dispose();
     return;
}
_axEdOffice.Dock = DockStyle.Fill;
stcWordTab.SelectedTab = item;
_axEdOffice.CreateNew("Word.Application");
_axEdOffice.WordDisableSaveHotKey(true);
string tempFileName = Path.GetTempFileName();
FileStream file = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite);
file.Close();
File.WriteAllText(tempFileName, temprtf, Encoding.UTF8);
_axEdOffice.WordInsertFile(tempFileName);
File.Delete(tempFileName);

我在网上搜索过,发现没什么用处。有谁知道导致这个问题的原因是什么?

0 个答案:

没有答案