By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

VSTO Outlook AddIn - Toolbar button Event Handler Fires One Time Only

P: n/a
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 -
May 22 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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 -

May 22 '06 #2

P: n/a
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 -


May 22 '06 #3

P: n/a
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 -
>
>



May 23 '06 #4

P: n/a
Sorry, we've already reached the boundaries of my knowledge! :-) Have you
tried posting your Property Pages problem on the Microsoft VSTO Forum? There
are a fair number of VSTO product team members and other experienced people
who read that forum:
http://forums.microsoft.com/MSDN/Sho...ID=16&SiteID=1

--
Harry Miller
This posting is provided "AS IS" with no warranties, and confers no rights.
"Joseph Geretz" <jg*****@nospam.com> wrote in message
news:u%****************@TK2MSFTNGP02.phx.gbl...
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 -
>
>



May 23 '06 #5

P: n/a
how do you build menu items and buttons?
Please be sure you declared all object in class not in method
boundaries.

there is huge possibility to be GC when you leave method boundaries

hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 23 '06 #6

P: n/a
OK, thanks. I've posted the question to the forum you suggest.

BTW, is this newsgroup for VSTO, or some other topic? I understood
vstools.office to indicate that this is the forum for VSTO.

Thanks,

- Joe Geretz -

"Harry Miller [MSFT]" <ha******@online.microsoft.com> wrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
Sorry, we've already reached the boundaries of my knowledge! :-) Have you
tried posting your Property Pages problem on the Microsoft VSTO Forum?
There
are a fair number of VSTO product team members and other experienced
people
who read that forum:
http://forums.microsoft.com/MSDN/Sho...ID=16&SiteID=1

--
Harry Miller
This posting is provided "AS IS" with no warranties, and confers no
rights.
"Joseph Geretz" <jg*****@nospam.com> wrote in message
news:u%****************@TK2MSFTNGP02.phx.gbl...
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 -
>> >
>> >
>>
>>
>
>



May 23 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.