CommandBarButton losing event

  • Thread starter Doug Buchanan [Exchange MVP]
  • Start date
D

Doug Buchanan [Exchange MVP]

I have written an add-in in C#. It uses a web service to transmit some
information. As soon as I create an instance of the web service, the
eventhandler that I added for the CommandBarButton's Click event is lost. The
application, commandbar and commandbarbutton are global in scope. If I "+="
the event back to the button, it works again. However, this has the
side-effect of potential multiple event firing as documents are opened,
closed, etc. Is there a known issue with this? Any ideas how to track down
what's happening? I'm not catching any errors, and the web service appears to
be doing exactly what it's supposed to...

Thanks!
Doug
 
K

Karsten Beck

I don't know if it's the same, but I had a similar (even a little bit more
complicated) problem:

I wrote a C# command-line application for testing automation features of MS
Word. I've used CommandBarButton objects of the original menu bar and saved
the references. After my command-line application has waited for a key event
the COM-wrapper of the CommandBarButton was lost. Each call to a property or
method failed with a COM-exception. It may be a similar problem: Your
CommandBarButton may be disposed internally by the Office application before
you can receive the event.

After I've copied the whole menu bar and substituted the original one, all
references (now to the copies) are working fine (use CommandBarControl.Copy
and traverse the whole menu bar). It seems to be an object lifetime problem
when you use the CommandBarButton object of the original menu bar. If Office
gains control back from your add-in or from my C# application it may perform
some kind of garbage collection. It seems to dispose reference objects to
its original CommandBarButtons, even if a consumer holds a reference to it.

Interesting whether Microsoft can confirm this strange behaviour.

Greetings
Karsten

"Doug Buchanan [Exchange MVP]"
 

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