P
Paul F. Williams
I created a C# Visio COM add-in using the interop DLL. The add-in inserts a
new top-level menu hierarchy into Visio's bar using CommandBar controls.
The menus appear and are functional... for a while.
Soon, the menu items stop invoking my event handlers. All of them stop
working at once, which leads me to believe that something may be getting
garbage collected. I tried making my handlers member variables-- to no
avail. There is no error message, not even when I turn on breaking on all
exceptions. They just doesn't work. I can let Visio sit a while after
startup, or I can open a document and work. It always happens.
Has anyone else seen this problem? What's happening to my event handlers?
Here is some sample code I use to create the menus:
CommandBarPopup dialogFlowMenu = (CommandBarPopup)menuBar.Controls.Add
(Microsoft.Office.Core.MsoControlType.msoControlPopup, Missing.Value,
Missing.Value, beforeControl.Index, Missing.Value);
dialogFlowMenu.Caption = "&Dialog";
dialogFlowMenu.Tag = DIALOG_MENU_TAG;
...
CommandBarButton exportMenu =
(CommandBarButton)dialogFlowMenu.Controls.Add
(MsoControlType.msoControlButton, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
exportMenu.Caption = "&Export";
exportMenu.Tag = DIALOG_MENU_EXPORT_TAG;
...
_CommandBarButtonEvents_ClickEventHandler exportHandler = new
_CommandBarButtonEvents_ClickEventHandler(exportMenu_Click);
exportMenu.Click += exportHandler;
new top-level menu hierarchy into Visio's bar using CommandBar controls.
The menus appear and are functional... for a while.
Soon, the menu items stop invoking my event handlers. All of them stop
working at once, which leads me to believe that something may be getting
garbage collected. I tried making my handlers member variables-- to no
avail. There is no error message, not even when I turn on breaking on all
exceptions. They just doesn't work. I can let Visio sit a while after
startup, or I can open a document and work. It always happens.
Has anyone else seen this problem? What's happening to my event handlers?
Here is some sample code I use to create the menus:
CommandBarPopup dialogFlowMenu = (CommandBarPopup)menuBar.Controls.Add
(Microsoft.Office.Core.MsoControlType.msoControlPopup, Missing.Value,
Missing.Value, beforeControl.Index, Missing.Value);
dialogFlowMenu.Caption = "&Dialog";
dialogFlowMenu.Tag = DIALOG_MENU_TAG;
...
CommandBarButton exportMenu =
(CommandBarButton)dialogFlowMenu.Controls.Add
(MsoControlType.msoControlButton, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
exportMenu.Caption = "&Export";
exportMenu.Tag = DIALOG_MENU_EXPORT_TAG;
...
_CommandBarButtonEvents_ClickEventHandler exportHandler = new
_CommandBarButtonEvents_ClickEventHandler(exportMenu_Click);
exportMenu.Click += exportHandler;