Outlook Add-In in C# -- the holy grail: Quitting Outlook causes problems

T

Terje Krång

Hi guys,

A lot of you are prolly getting tired of this question, and will ask me to
take a look at the ItemsCB example or something. Believe me, I've done that.
And I have tried GC.WaitForPendingFinalizers() and every other tip I've come
across. It doesn't help, no matter what I do, Outlook will not quit
properly. It does quit, but consequently when having the add-in loaded,
Outlook uses about 6-7 seconds to quit. When the add-in is not loaded, it
takes less than 1 second.

To see an example of the code, take a look at the add-in described on the
following URL.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnout2k2/html/odc_oladdinvbnet.asp

.... or open this example project: (Visual Studio 2003)

http://www.dreamscape.no/OutlookAddInTest.zip

Now, does anyone have an explanation on how to get rid of this problem? What
makes it even worse is that when trying to start Outlook (2003) when closing
the previous instance, I get a message saying something like "The operation
failed.".


Best Regards,
Terje Krång, Junglemap
(e-mail address removed)
 
T

Tom Rizzo [MSFT]

And you're sure you're wiping out your references to all your Outlook
Objects?

Tom
 
T

Terje Krång

Well, I've done several things to try to ensure that all objects are wiped
out. What boggles me is that even if my Connect class does not contain a
single member variable, only automatic variables, once I call
application.ActiveExplorer() (I don't even need to store it in a variable)
Outlook uses 6-7 seconds to close.

I've also tried wiping out everything by handling the Explorers Close-event
like this:
private void OnExplorerClose()
{
toolbarButton.Delete(System.Reflection.Missing.Value);

DisposeObject(applicationObject);
DisposeObject(addInInstance);
DisposeObject(toolbarButton);

applicationObject = null;
addInInstance = null;
toolbarButton = null;

GC.WaitForPendingFinalizers();
GC.Collect();
}

... still 6-7 seconds to close :(


Terje
 
T

Terje Krång

Sorry, forgot to mention that my DisposeObject function looks like this:

private static void DisposeObject(object o)
{
while (Marshal.ReleaseComObject(o) > 0);
}

This is just something I picked up from some VB-article and translated to
C#, I don't know if it has any effect at all. I've tried all sorts of
combinations using DisposeObject, setting member variable to null, not using
member variables at all -- no matter what I do, Outlook uses 6-7 seconds.

Oh, I should prolly mention that I am using the PIA for Outlook 2002, but
testing it on Outlook 2003. Could this cause the problems I am experiencing?
I would really like to compile just one build that will work for both
Outlook versions.


Terje
 
T

Tom Rizzo [MSFT]

And how long does Outlook take without your add-in? Outlook writes out
free/busy, etc on shutdown to the server and that could take a bit.

Also, you may want to walk the Explorers and Inspectors collections to see
if any are hanging around and close them explicitly.

Tom

--
Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp

This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Terje Krång

I am using Outlook without being connected to Exchange, so it shouldn't
communicate with server on close. Without the add-in, outlook.exe process
dissapears within 1 second.

Anyways ... WTF!!! You're not gonna believe this. I fumbled around a bit
inside OnExplorerClose(), my Explorer Close event handler, trying to find
out if there was any Explorers or Inspectors hanging around. Both
collections counted 0 elements. However, when adding the following line as
the first line in the method, OUTLOOK.EXE dissapears immediately, just as if
the add-in wasn't loaded at all -- but it is!! Problem solved, but how could
this line make a difference?

Debug.WriteLine("OnExplorerClose()"); // could of course write any string
....

I really don't like this solution, because I do not understand why it is a
solution and I can't believe it is reliable. When my add-in is installed on
hundreds of clients, I'm willing to bet that outlook.exe will hang 6-7
seconds on some of them.


Terje
 
T

Terje Krång

As I suspected, when compiling this on another machine (with the same
development environment), the Debug.Write fix did not work anymore.

Back to square one... Outlook process continues for 6-7 seconds after
I close Outlook when add-in is loaded, <1 sec when not loaded.

Does anyone have a working example of a simple Hello World add-in?
That is, an example where add-in can be loaded and Outlook still
exits as normal?


Terje
 
T

Tom Rizzo [MSFT]

And you're using the Office PIAs? You're sure you don't have a huge for
loop that finds all the prime numbers to a billion or something like that in
your disconnect event handler :) Just a shot in the dark.

Tom

--
Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top