Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. VSTO outlook stopping fire events while running...?

VSTO outlook stopping fire events while running...?

Scheduled Pinned Locked Moved C#
helpcomtutorialquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leeoze 0
    wrote on last edited by
    #1

    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)
    {

    _ 1 Reply Last reply
    0
    • L leeoze 0

      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)
      {

      _ Offline
      _ Offline
      _Erik_
      wrote on last edited by
      #2

      See remarks here[^]

      L 1 Reply Last reply
      0
      • _ _Erik_

        See remarks here[^]

        L Offline
        L Offline
        leeoze 0
        wrote on last edited by
        #3

        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

        _ 2 Replies Last reply
        0
        • L leeoze 0

          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

          _ Offline
          _ Offline
          _Erik_
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • L leeoze 0

            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

            _ Offline
            _ Offline
            _Erik_
            wrote on last edited by
            #5

            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.

            L 1 Reply Last reply
            0
            • _ _Erik_

              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.

              L Offline
              L Offline
              leeoze 0
              wrote on last edited by
              #6

              tnx. BTW should I do the same for Application.ItemContextMenuDisplay event? i.e. private this.Application app; .. { app.ItemContextMenuDisplay += new... } ???

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups