Thanks Harry - that's exactly it!
(Heh - this former ActiveX developer just survived his first collision with
the .NET Garbage Collector! ;-)
Explain one thing to me, though. I had assumed that Outlook's reference to
this button (after all the button does remain on Outlook's toolbar) would be
enough to keep this object around. Isn't my event handler set to handle
events from a button created and maintained by Outlook (on my behalf of
course). Why is this insufficient?
It's also very interesting, that my previous implementation of this project,
which used Extensibility (Extensibility.IDTExtensibility2) rather than VSTO
was not succeptible to GC in this regard. I only started losing my events
when I converted my implementation to use VSTO.
Thanks for your help! Can you help me with my Property Page problem (post
directly above this one)?
Thanks!
- Joe Geretz -
"Harry Miller [MSFT]" <ha******@online.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
The object might be getting garbage-collected. Have a look at this blog
post
and see if it applies to your situation.
http://blogs.msdn.com/vsto/archive/2.../29/64449.aspx
--
Harry Miller
This posting is provided "AS IS" with no warranties, and confers no
rights.
"magne" <ma***@nospam.nospam> wrote in message
news:uZ**************@TK2MSFTNGP03.phx.gbl... Hello Joseph
Please have a look at my thread from today 12:00 (local time), subject
"VSTO 2005 problems".
I wonder if we have the same problem.
I found a weired "solution" by adding a gc collect just after the event
handler wireup logic (...Click += ...), could you try something similar
and see if it has effect ?
"Joseph Geretz" <jg*****@nospam.com> wrote in message
news:up**************@TK2MSFTNGP03.phx.gbl... > I'm porting a C# Outlook Addin originally engineered as a COM Addin
> over
> to use VSTO. I've gotten this to the point where my VSTO Addin installs
> its Menu items and Toolbar buttons when Outlook launches. I've wired up my > event handler to each Menu item and toolbar button. (I use the same Event > handler and I use the Tag property which is different for every Menu Item > and Toolbar buton to determine which menu or button is being clicked
> and
> to take appropriate action. This worked fine for me previously.)
>
> However I'm seeing a very strange behavior: My event handler is fired for > the first toolbar or menu click. But then it never fires thereafter. It's > like after it fires once, it gets 'unhooked' form the event its
> supposed
> to be handling. A breakpoint set in this handler isn't tripped.
>
> Here's the code which wires up the Event handler:
>
> tbButton.Click += new
> Office._CommandBarButtonEvents_ClickEventHandler(t his.User_Click);
> MenuItem.Click += new
> Office._CommandBarButtonEvents_ClickEventHandler(t his.User_Click);
>
> Here's the Event handler which fires once:
>
> private void User_Click(Office.CommandBarButton cmdButton, ref bool
> cancel)
> {
> MessageBox.Show("Hello!");
> }
>
> Have you seen anything like this before? Is there something I need to
> do
> to 'reset' the Event handler after it completes? I'm completely
> puzzled.
> Bear in mind that this was working beautifully when running as a COM
> Addin.
>
> Thanks for your help,
>
> - Joseph Geretz -
>
>