outlook - Outlook VSTO 正确处理 SelectionChange(当前双击崩溃插件)
问题描述
据我了解,您需要跟踪 Explorer 的激活和停用。在激活期间,您需要为当前资源管理器添加 SelectionChange 事件处理程序。这似乎非常适合单击 AppointmentItems。但是当双击一个约会系列并选择一个约会时,它会使插件崩溃。
这是来源:在课堂上
private Outlook.Explorer currentExplorer = null;
private Outlook.AppointmentItem currentAppointmentItem = null;
在启动中:
currentExplorer = this.Application.ActiveExplorer();
((Outlook.ExplorerEvents_10_Event)currentExplorer).Activate +=
new Outlook.ExplorerEvents_10_ActivateEventHandler(
Explorer_Activate);
currentExplorer.Deactivate += new
Outlook.ExplorerEvents_10_DeactivateEventHandler(
Explorer_Deactivate);
事件处理程序:
void Explorer_Activate()
{
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(Selection_Change);
}
void Explorer_Deactivate()
{
currentExplorer.SelectionChange -= new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(Selection_Change); ;
}
private void Close_Explorer()
{
}
private void Selection_Change()
{
Outlook.MAPIFolder selectedFolder = currentExplorer.CurrentFolder;
if (currentExplorer.Selection.Count > 0)
{
Object selObject = currentExplorer.Selection[1];
if (selObject is Outlook.AppointmentItem)
{
currentAppointmentItem = (Outlook.AppointmentItem)selObject;
}
else
{
currentAppointmentItem = null;
}
}
}
我在看什么?注销的形式有问题吗?
解决方案
尝试将 try/catch 块添加到事件处理程序。Outlook 对象模型有时会给您带来不可预知的结果。值得添加它们并找到引发异常的位置。
currentExplorer.Selection.Count
SelectionChange
此外,您可以在NewExplorer事件中订阅该事件,并且在激活或停用资源管理器时不要在资源管理器之间切换。每当打开一个新的资源管理器窗口时都会触发该事件,无论是作为用户操作的结果还是通过程序代码。
推荐阅读
- groovy - 将令牌从获取请求传递到 SoapUI 中的标头
- html - 为什么我的底部 div 与我的另一个 div 重叠而不是堆叠?
- java - 骆驼:无法找到 XML 模式命名空间的 Spring NamespaceHandler [http://camel.apache.org/schema/spring]
- javascript - 有没有办法通过javascript更改outlook中的地址?
- c - 如何在字符数组中存储多组字符串
- macos - Xamarin.Forms macOS 启动画面
- node.js - 通过 NodeJS 开发工具包 (aws-sdk-js) 拒绝访问 AWS SQS(突然!!)
- java - 将输入列表与存储库对象列表进行比较:循环执行需要更多时间
- xcode - Xcode 为 ARKit 将 3d 模型转换为 DAE 格式的问题
- c++ - 静态数组的免费动态数组?