none
Removing user interface from my Outlook 2007 add-in and implementing timer-driven operation instead RRS feed

  • Question

  • This is a request for advice on the feasibility of changing the behavior of an Outlook 2007 add-in I developed. 

    Currently, the "operations" of the add-in are triggered by the user clicking on a button I added to the Office.CommandBar:

     private void buttonOne_Click(Office.CommandBarButton ctrl, ref bool cancel)
     {
      // Retrieve the name of the top-level folder (Inbox); Cast the MAPI folder returned as an Outlook folder
      Outlook.Folder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder; 
      // Retrieve a reference to the top-level folder. 
      if (inbox != null)
      {
      Outlook.Folder parent = inbox.Parent as Outlook.Folder; // the mailbox itself
      if (parent != null)
      {
       _Special_archiveFolder = LocateSpecial_Archives(parent);
       RecurseThroughFolders(parent, 0);        // upload all detected msgs via webservice 
      }
      }
     }
    
    

    "Operations" are traversing through a defined set of folders subordinate to the INBOX and using a webservice I wrote to upload the email messages and any attachments to a records-management server. This, thankfully, is working nicely as it is.  

    I'm seeking advice on an enhancement I'm contemplating and wondering if some VSTO experts could see any flaws or "gotcha's" in this approach:

    1. Remove the button completely 
    2. Replace with some timer-driven code that "wakes" at some interval and "looks for work to do" (via my current code above marked by the method called: RecurseThroughFolders(parent, 0);
    3. Dedicate one of our current virtual workstation PCs to be this "Outlook drone worker" (figuring out how to automatically logon to Outlook as some sort of startup task or script).
    4. Configure this Outlook session to automatically retrieve email from our email server at some specified interval (we do not use Exchange)
    5. Configure the add-in logic sketched in the snippet above to wake up at some time interval and do it's thing and go back to sleep.

     

    There may be better ways to accomplish this but I am hoping that if I can resolve item 3 and keep the bulk of my current code then items 4 and 5 I suspect would be possible. 

    Looking forward to your advice. Thanks.


    John

    Thursday, June 9, 2011 5:07 PM

Answers

  • That's a design that will cause all sorts of problems.
     
    Outlook is not suited for use in unattended operations, or for use in a service or scheduled task. In many cases even trying to start an Outlook Application object under those conditions will just fail. If it works Outlook still can't be configured to not display warnings or errors.
     
    The Outlook object model is single-threaded and all object model calls must run on the main addin thread which is the same thread Outlook uses. If you use a timer you must make sure it runs on the main thread or synch to that thread context.
     
    If you want to do that sort of thing you should use a MAPI library such as Redemption (www.dimastr.com/redemption) with server side MAPI installed and run it as a service or console app started by the timer. That can be multithreaded and work without UI and from a service or scheduled task.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "daniella_mercury_fan" <=?utf-8?B?ZGFuaWVsbGFfbWVyY3VyeV9mYW4=?=> wrote in message news:5dffcd3b-af51-4d19-9e19-6debc8e8ed8b...

    This is a request for advice on the feasibility of changing the behavior of an Outlook 2007 add-in I developed. 

    Currently, the "operations" of the add-in are triggered by the user clicking on a button I added to the Office.CommandBar:

     private void buttonOne_Click(Office.CommandBarButton ctrl, ref bool cancel)
     {
     // Retrieve the name of the top-level folder (Inbox); Cast the MAPI folder returned as an Outlook folder
     Outlook.Folder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder; 
     // Retrieve a reference to the top-level folder. 
     if (inbox != null)
     {
     Outlook.Folder parent = inbox.Parent as Outlook.Folder; // the mailbox itself
     if (parent != null)
     {
      _Special_archiveFolder = LocateSpecial_Archives(parent);
      RecurseThroughFolders(parent, 0);    // upload all detected msgs via webservice 
     }
     }
     }
    
    

    "Operations" are traversing through a defined set of folders subordinate to the INBOX and using a webservice I wrote to upload the email messages and any attachments to a records-management server. This, thankfully, is working nicely as it is.  

    I'm seeking advice on an enhancement I'm contemplating and wondering if some VSTO experts could see any flaws or "gotcha's" in this approach:

    1. Remove the button completely 
    2. Replace with some timer-driven code that "wakes" at some interval and "looks for work to do" (via my current code above marked by the method called: RecurseThroughFolders(parent, 0);
    3. Dedicate one of our current virtual workstation PCs to be this "Outlook drone worker" (figuring out how to automatically logon to Outlook as some sort of startup task or script).
    4. Configure this Outlook session to automatically retrieve email from our email server at some specified interval (we do not use Exchange)
    5. Configure the add-in logic sketched in the snippet above to wake up at some time interval and do it's thing and go back to sleep.

     

    There may be better ways to accomplish this but I am hoping that if I can resolve item 3 and keep the bulk of my current code then items 4 and 5 I suspect would be possible. 

    Looking forward to your advice. Thanks.


    John


    Ken Slovak MVP - Outlook
    Thursday, June 9, 2011 6:37 PM

All replies

  • That's a design that will cause all sorts of problems.
     
    Outlook is not suited for use in unattended operations, or for use in a service or scheduled task. In many cases even trying to start an Outlook Application object under those conditions will just fail. If it works Outlook still can't be configured to not display warnings or errors.
     
    The Outlook object model is single-threaded and all object model calls must run on the main addin thread which is the same thread Outlook uses. If you use a timer you must make sure it runs on the main thread or synch to that thread context.
     
    If you want to do that sort of thing you should use a MAPI library such as Redemption (www.dimastr.com/redemption) with server side MAPI installed and run it as a service or console app started by the timer. That can be multithreaded and work without UI and from a service or scheduled task.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "daniella_mercury_fan" <=?utf-8?B?ZGFuaWVsbGFfbWVyY3VyeV9mYW4=?=> wrote in message news:5dffcd3b-af51-4d19-9e19-6debc8e8ed8b...

    This is a request for advice on the feasibility of changing the behavior of an Outlook 2007 add-in I developed. 

    Currently, the "operations" of the add-in are triggered by the user clicking on a button I added to the Office.CommandBar:

     private void buttonOne_Click(Office.CommandBarButton ctrl, ref bool cancel)
     {
     // Retrieve the name of the top-level folder (Inbox); Cast the MAPI folder returned as an Outlook folder
     Outlook.Folder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder; 
     // Retrieve a reference to the top-level folder. 
     if (inbox != null)
     {
     Outlook.Folder parent = inbox.Parent as Outlook.Folder; // the mailbox itself
     if (parent != null)
     {
      _Special_archiveFolder = LocateSpecial_Archives(parent);
      RecurseThroughFolders(parent, 0);    // upload all detected msgs via webservice 
     }
     }
     }
    
    

    "Operations" are traversing through a defined set of folders subordinate to the INBOX and using a webservice I wrote to upload the email messages and any attachments to a records-management server. This, thankfully, is working nicely as it is.  

    I'm seeking advice on an enhancement I'm contemplating and wondering if some VSTO experts could see any flaws or "gotcha's" in this approach:

    1. Remove the button completely 
    2. Replace with some timer-driven code that "wakes" at some interval and "looks for work to do" (via my current code above marked by the method called: RecurseThroughFolders(parent, 0);
    3. Dedicate one of our current virtual workstation PCs to be this "Outlook drone worker" (figuring out how to automatically logon to Outlook as some sort of startup task or script).
    4. Configure this Outlook session to automatically retrieve email from our email server at some specified interval (we do not use Exchange)
    5. Configure the add-in logic sketched in the snippet above to wake up at some time interval and do it's thing and go back to sleep.

     

    There may be better ways to accomplish this but I am hoping that if I can resolve item 3 and keep the bulk of my current code then items 4 and 5 I suspect would be possible. 

    Looking forward to your advice. Thanks.


    John


    Ken Slovak MVP - Outlook
    Thursday, June 9, 2011 6:37 PM
  • Hi John,

    Have a look at Ken's  reply which will be helpful to resolve your question.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 16, 2011 3:56 AM
    Moderator