VSTO outlook stopping fire events while running...?
-
Hi I'm writing an outlook addin in VisuaStudio 2008 using the buildin Outlook addin project template of VS2008. In my code I added a new button to one of the ActiveExplorer() commandbars. I made it changed according to the number of items selected in the ActiveExplorer using Application.ActiveExplorer().SelectionChange event. this works just fine up until I click on the button and load my winForm. after doing so it seems like the Application events that I used (including : SelectionChange and ItemContextMenuDisplay) stopped triggered. and the button as a result stopped changing according to the number of items selected. The winform is empty and loads up as ShowDialog. Any ideas why and how to fix it? tnx leeoz here is part of the relevant code (I only missed out the AddMenuBar(), ThisAddIn_Shutdown() and the other events which have the same problem after showing this winForm):
private void InternalStartup()
{
this.Application.ItemContextMenuDisplay +=new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(Application_ItemContextMenuDisplay);
this.Application.ContextMenuClose +=new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ContextMenuCloseEventHandler(Application_ContextMenuClose);
this.Application.ActiveExplorer().SelectionChange += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ThisAddIn_SelectionChange);
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}void ThisAddIn_SelectionChange()
{
if (btnManualFiling != null)
{
if (this.Application.ActiveExplorer().Selection.Count > 0)
{btnManualFiling.Enabled = true; } else { btnManualFiling.Enabled = false; } CurrentSelection = this.Application.ActiveExplorer().Selection.Count.ToString(); btnManualFiling.Caption = TomaxManCaption + "(" + CurrentSelection + " items)"; } }
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
AddMenuBar();
}private void buttonOne_Click(Office.CommandBarButton ctrl, ref bool cancel)
{ -
Hi I'm writing an outlook addin in VisuaStudio 2008 using the buildin Outlook addin project template of VS2008. In my code I added a new button to one of the ActiveExplorer() commandbars. I made it changed according to the number of items selected in the ActiveExplorer using Application.ActiveExplorer().SelectionChange event. this works just fine up until I click on the button and load my winForm. after doing so it seems like the Application events that I used (including : SelectionChange and ItemContextMenuDisplay) stopped triggered. and the button as a result stopped changing according to the number of items selected. The winform is empty and loads up as ShowDialog. Any ideas why and how to fix it? tnx leeoz here is part of the relevant code (I only missed out the AddMenuBar(), ThisAddIn_Shutdown() and the other events which have the same problem after showing this winForm):
private void InternalStartup()
{
this.Application.ItemContextMenuDisplay +=new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(Application_ItemContextMenuDisplay);
this.Application.ContextMenuClose +=new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ContextMenuCloseEventHandler(Application_ContextMenuClose);
this.Application.ActiveExplorer().SelectionChange += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ThisAddIn_SelectionChange);
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}void ThisAddIn_SelectionChange()
{
if (btnManualFiling != null)
{
if (this.Application.ActiveExplorer().Selection.Count > 0)
{btnManualFiling.Enabled = true; } else { btnManualFiling.Enabled = false; } CurrentSelection = this.Application.ActiveExplorer().Selection.Count.ToString(); btnManualFiling.Caption = TomaxManCaption + "(" + CurrentSelection + " items)"; } }
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
AddMenuBar();
}private void buttonOne_Click(Office.CommandBarButton ctrl, ref bool cancel)
{ -
So I have read this and know all of this before... Still no answer to my question. I understand that while the dialog is open the owner is puaused untill I close the dialog. But my problem is after I close the dialog, the addin is still running ok, but all the events I've added from the beggining stopped from firing (i.e. while I change my selection I don't get the event to fire again). Why and how to fix this, I don't know...?! tnx
-
So I have read this and know all of this before... Still no answer to my question. I understand that while the dialog is open the owner is puaused untill I close the dialog. But my problem is after I close the dialog, the addin is still running ok, but all the events I've added from the beggining stopped from firing (i.e. while I change my selection I don't get the event to fire again). Why and how to fix this, I don't know...?! tnx
Ok, I missunderstood your first post. Have you manually modified the InternalStartup method implementation to add the other event handlers? You shouldn't. It is better to place that into your Startup event handler. Anyway, I have made a little plugin to test and get the same problem as you. I will try to find out what is going on and will tell you if I find something.
modified on Tuesday, October 26, 2010 11:02 AM
-
So I have read this and know all of this before... Still no answer to my question. I understand that while the dialog is open the owner is puaused untill I close the dialog. But my problem is after I close the dialog, the addin is still running ok, but all the events I've added from the beggining stopped from firing (i.e. while I change my selection I don't get the event to fire again). Why and how to fix this, I don't know...?! tnx
Ok, I can tell you how to fix it, though I can't tell you why, and after so many years fighting against MS-Outlook API, I have learned to yield in some cases and just look for a good work around. Instead of this line you have:
Application.ActiveExplorer().SelectionChange += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ThisAddIn_SelectionChange);
Use a class level field to hold the explorer, and then set the event handler on it:
Microsoft.Office.Interop.Outlook.Explorer exp;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
exp = Application.ActiveExplorer();
exp.SelectionChange += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ThisAddIn_SelectionChange);
...
}It works this way... Don't ask me why... I just don't even want to know.
-
Ok, I can tell you how to fix it, though I can't tell you why, and after so many years fighting against MS-Outlook API, I have learned to yield in some cases and just look for a good work around. Instead of this line you have:
Application.ActiveExplorer().SelectionChange += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ThisAddIn_SelectionChange);
Use a class level field to hold the explorer, and then set the event handler on it:
Microsoft.Office.Interop.Outlook.Explorer exp;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
exp = Application.ActiveExplorer();
exp.SelectionChange += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ThisAddIn_SelectionChange);
...
}It works this way... Don't ask me why... I just don't even want to know.