共享插件(当前为 Outlook)- 工具栏按钮可以工作一点,然后停止,没有给出错误
有点奇怪的是:我有一个共享的 Office 插件,当前针对 XP 和 Win7 上的 Outlook 2007(Excel/Word 和其他版本)。它添加了一个工具栏按钮,这会触发我的代码。我的代码只是从 Outlook 读取数据。第一次,它很有效。第二次,单击按钮没有任何反应。没有错误,什么都没有。 Outlook 的其余部分将正常响应。
整个事件代码位于 try/catch 中,该 try/catch 将任何异常写入临时文件(如果代码中抛出异常,则此机制有效),但不会拾取任何内容。
根据“信任中心”,我的插件处于活动状态(不是不活动或禁用)。如果我重新启动 Outlook,或通过信任中心停止并启动插件,它会再次运行一次然后停止。
如果我减少代码所做的工作量,该按钮有时会响应大约十次点击左右,然后放弃。无论我尝试使用哪个版本的代码,资源似乎都没有太大变化(内存增加了一点点,线程数保持不变)。
我读过有关 Word 的类似内容,但这是通过 Word 每次加载文档时重新创建工具栏或菜单来解释的(不确定这是否正确)。对我来说,我选择一封电子邮件,单击一次,它起作用了,再次单击(没有更改 Outlook 中的视图,选择不同的电子邮件等),但它不起作用。
有人在这里得到任何线索吗?
Bit of a weird one this: I've got a shared Office addin that currently targets Outlook 2007 on XP and Win7 (Excel/Word and other versions later). It adds a toolbar button, and this fires off my code. My code just reads data from Outlook. First time round, it works a treat. Second time, the button click does nothing. No errors, nothing. The rest of Outlook responds as normal.
The entire event code is in a try/catch that writes any exceptions out to a temporary file (this mechanism works if a throw an exception in code), but nothing is picked up.
According to the "Trust Center", my addin is active (not inactive or disabled). If I restart Outlook, or stop and start the addin via the Trust Center, it again works once and then stops.
If I reduce the amount of work my code does, the button will sometimes respond for about ten clicks or so, then gives up. Whichever version of my code I try, resources don't seem to change much (memory moves up a mite, the thread count stays the same).
I've read of a similar thing with Word, but this was explained by Word recreating the toolbars or menus every time it loads a document (not sure how correct this is). For me, I select an email, click once, it works, click again (no changing views in Outlook, selecting different emails, etc), and it doesn't.
Has anybody got any clues here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将包含工具栏按钮的变量放置到全局范围内(您可以将其保留为插件对象的字段)。如果您没有始终保留它们的有效路径,.NET 垃圾收集器最终将清理这些对象及其事件处理程序。但是,这不会删除可见按钮,因此它仍然可见。
You should place the variable that contains your toolbar buttons to a global scope (You can keep then as fields of the addin object). If you don't keep a valid path to them at all times, .NET garbage collector will eventually clean up these objects and the event handlers with it. This will however not remove the visible button so it will still be visible.