0
votes

currently I'm developing a small VSTO Outlook Add-In. While I've some experience in C#, I'm not very familiar with the Outlook object model.

The scope of my Add-In is pretty easy. My colleagues and I have a shared Outlook inbox (beside our own ones). The shared inbox has categories and subfolders with the same name. E.g. there’s a subfolder “Michael” and there exists a category “Michael”. When somebody applies his own category to a mail in the shared inbox, the mail is automatically moved to the matching subfolder, the reply window opens and the sender address is changed from the shared email address to the personal one (our IT adjusted the shared mail address to not be able to send emails).

Right now the current version of the Add-In works flawlessly, beside the fact that it somehow stops to work after some time. So when I start outlook, everything works like expected, I can categorize mails in the shared inbox and they’re moved etc. But after some time (sometimes hours, sometimes even after 30 minutes) it’s not working anymore. Neither the debug view in Visual Studio nor Outlook are indicating any errors. At first I thought something terminated my Add-In, but then I configured a timer to send a “I’m alive” message to the log file and now I can see that the Add-In is still running.

Hence I assume that somehow the events I’ve registered to are not sufficient to keep track of the users action in Outlook. This can be confirmed as a break point in the event handlers is not triggered when this behavior appears and a mail is categorized. I’ve registered to the following events in the startup method:

Outlook.Application application = this.Application;
Outlook.Inspectors inspectors = application.Inspectors;
Outlook.Explorer activeExplorer = this.Application.ActiveExplorer();
// When a new mail is created, trigger Inspectors_AddTextToNewMail() methode
inspectors.NewInspector = new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_AddTextToNewMail);
// Whenever something in the explorer is selected, run the event handler
activeExplorer.SelectionChange += ActiveExplorer_SelectionChange;

In the selectionChange() Event-Handler another Event-listener for the change of the mail properties is registered:

Outlook.MailItem mailItem = selectedItem as Outlook.MailItem;
// Register an Event handler that listens for changes of the mailitem's properties in order to check the category
mailItem.PropertyChange += MailItem_PropertyChange;

This way I can check whether a category has been applied.

But after some time not even the ActiveExplorer_SelectionChange Event is triggered, independent on what I select in Outlook.

Does anybody know whether I missed something? Do I have to register to further events so the Add-In won’t lose track?

Thanks for your help in advance!

Best Regards,

Percy

1
how long is "sometime"? ive got an almost identical thing that runs for months.. until windows insists I reboot. chances are something is silently faulting.. make sure you have enough checks and loggingBugFinder
This morning I noticed after 30 minutes that the Add-In stopped working. Yesterday it worked till the end of the day without any issues. In the meantime I've added a lot of debug information (console) and a log-file. When the add-in stops working, no new entries are generated. Only the "I'm alive" log entry which is created by a timer I initialize in the startup() method is still generated. Do you think a global exception handling over the whole code might indicate the issue?Percy
Sadly then the problem lies somewhere in your code in that the addin is still there, its just disappeared eating its own tail doing "something" and its the "something" only you can really address - for example, mine monitors for new mails, depending on the mail, makes if necessary a directory and saves the mail, if this all takes too long it can barf so i had to do some funkyness to make it think it was done when it wasnt but it was still doing it with awaits and so on.BugFinder

1 Answers

0
votes

You need to declare the variables application, inspectors and activeExplorer on the global (class) level to prevent them from being released by the Garbage Collector.