【发布时间】:2017-08-18 19:42:41
【问题描述】:
我正在尝试解决我的 Excel 加载项中的问题,即当我的用户退出 Excel 时 Excel 卡在进程中。
我注意到在添加 CustomTaskPane 后问题开始发生,然后当我尝试关闭 Excel 时,它并没有完全退出并停留在任务管理器中。但是,如果我在添加 CustomTaskPane 之前关闭 Excel,Excel 会正确关闭。
这里只是一个关于如何添加 CustomTaskPane 的简单代码,它只是一个简单的空白任务窗格。
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
var host = new ElementHost();
host.Dock = DockStyle.Fill;
var taskPaneControl = new UserControl();
taskPaneControl.Controls.Add(host);
var taskPaneValue = CustomTaskPanes.Add(taskPaneControl, "My TaskPane");
taskPaneValue.Visible = true;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
Office.CommandBar taskBar = null;
try
{
taskBar = Application.CommandBars["Task Pane"];
taskBar.Reset();
}
finally
{
if (taskBar != null)
{
Marshal.ReleaseComObject(taskBar);
taskBar = null;
}
}
}
至于ThisAddIn_Shutdown方法,不管该函数是否为空,Excel仍然无法正常关闭。
添加 CustomTaskPane 后 Excel 无法正常关闭是什么问题?
请指教,谢谢!
【问题讨论】:
-
AFAIK 任务/操作窗格有此类问题的历史记录,您很有可能找不到好的答案。您可以尝试不同的 VSTO 版本和/或 Office 应用程序/版本。 MSDN 论坛可能也有一些东西。