CommandBars.OnUpdate停止触发 [英] CommandBars.OnUpdate stops being fired
问题描述
在我的PowerPoint 2010 Addin中,我订阅了 CommandBars.OnUpdate
事件来注册形状和类似事件的移动:
In my PowerPoint 2010 Addin I subscribed to the CommandBars.OnUpdate
event to register movement of shapes and similar events:
ppt = Globals.ThisAddIn.Application;
ppt.CommandBars.OnUpdate += CommandBars_OnUpdate;
这段时间很好。但是,最终事件停止被解雇。那么,至少注册的事件处理程序没有被调用。我不清楚,是什么原因导致这种行为。看起来有点不确定。调试输出中不会出现异常。看来,这种情况发生在一段时间之后,不是由用户操作引起的。
This works great for some time. However, eventually the event stops being fired. Well, at least the registered event handler is not being called. I couldn't figure out, what causes this behaviour. It seems a bit indeterministic. No exception is thrown that would appear in the Debug output. It seems, this happens after some time and is not caused by a user action.
我假设,这是由于 CommandBars
对象。所以我添加了一个定时器,它检查这些更改。但是,与最后一个对象的比较, ==
和 .Equals()
会导致每个刻度的识别更改,即非常不太可能。
I assumed, this would be due to a change of the CommandBars
object. So I added a timer, which checked for those changes. But both ==
and .Equals()
comparisons to the last object result in a recognized change every tick, which is very unlikely.
我也试图定期刷新事件处理程序(每1分钟),但这也不行:
I also tried to refresh the event handler periodically (every 1 minute), but this doesn't work either:
ppt.CommandBars.OnUpdate -= CommandBars_OnUpdate;
ppt.CommandBars.OnUpdate += CommandBars_OnUpdate;
事件真的在一段时间后停止吗?有没有其他方法可以检测物体移动,调整大小,删除等?
Does the event really stop after some time? Is there any other method to detect object movement, resize, deletion etc.?
同时我重组了加载项。我现在能够重现这个问题。这是如何:
In the meanwhile I restructured the addin. I am now able to reproduce the problem. Here is how:
在加载项的功能区中,我有一个按钮,它调用方法 CreateRightEyeCopy()
视图模型。在该方法中,调用ViewModel的另一种方法 GetNextPairId()
。这个电话似乎有问题。我更改了 GetNextPairId()
以立即返回0,以确保该方法是问题。
In the addin's ribbon I have a button, which calls the method CreateRightEyeCopy()
on the ViewModel. In this method another method GetNextPairId()
of the ViewModel is called. And this call seems problematic. I changed the GetNextPairId()
to immediately return 0 to ensure that the method is the problem.
这是 return 0
line
ViewModel.GetNextPairId()
[External Code]
ViewModel.CreateRightEyeCopy()
Button's event handler
$ b $我不知道为什么我的两个功能之间有外部代码。这个代码可以导致 OnUpdate
事件停止吗?
如果有人有兴趣,这里是两个函数的代码:
If someone's interested, here is the code of the two functions:
CreateRightEyeCopy()
:
try
{
var sel = ppt.ActiveWindow.Selection;
if (sel.Type == PpSelectionType.ppSelectionShapes)
{
foreach (Shape s in sel.ShapeRange)
{
var pair = FindStereoPair(s);
//Only add a new pair, if shape is not in a pair already
if (pair == null)
{
// ** return; **
int id = GetNextPairId(s.Parent);
return; //for debugging purposes
}
}
}
}
catch (Exception x)
{
Debug.WriteLine("Exception occured during creation of stereo pair: " + x.Message);
}
GetNextPairId()
:
return 0;
如果在调用 GetNextPairId()
然后 OnUpdate
继续。
我还试图调用 CreateRightEyeCopy ()
异步地,但这并不改变任何东西。
I also tried to invoke CreateRightEyeCopy()
asynchronously, but that doesn't change anything.
在这个问题上是否有进一步的想法?
Are there any further thoughts on this issue?
推荐答案
不是真正的答案,而是 MSDN说:强烈建议此事件主要用于检查COM AddIn中添加或删除的自定义命令栏。
Not a real answer but MSDN says: "It is strongly recommended that this event be used primarily for checking that a custom command bar has been added or removed by a COM AddIn."
您应该选择不同的方法来跟踪其他事件。
You should probably choose a different approach to track other events.
作为事后,您确定您捕获所有异常(UnhandledException,ThreadException )?
As an afterthought, are you sure you are capturing all exceptions (UnhandledException, ThreadException)?
这篇关于CommandBars.OnUpdate停止触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!