473,287 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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

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
6 8733
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jaime Rios | last post by:
Hi, I created a COM AddIn for Word that performs the functions that it needs to, but I needed to add the ability for the toolbar created by the COM AddIn to remember it's last position and...
4
by: Max | last post by:
Hi, I would like to have a button and a combo box with options to select various versions of Microsoft Outlook: 2002, 2003. The user selects the email client and clicks the button. The only...
1
by: Stan | last post by:
If a page has a button with event handler private void btnAdd_Click(object sender, System.EventArgs e) { ....... } this event handler fires every time I refresh the page in the browser with...
4
by: damian | last post by:
Help! I created a COM addin using vb.net based on the KB article 302896 (http://support.microsoft.com/default.aspx?scid=kb;en-us;302896). The problem is Outlook remains in memory when after it. I...
13
by: Howard Kaikow | last post by:
I just visited the MSFT web site and saw the comparison/pricing of the different VS 2005 versions. I was looking for a statement of the system requirements for VS Pro and VSTO, could not find. ...
0
by: guilligan.geo | last post by:
Hello, I'm trying to create an addin for Outlook 2002 using the one provided in the demo of win32com as a starting point. I've been able to do my addin and test it if I go the "standard" way...
2
by: Peted | last post by:
Hi Im using c# express edition 2005 I have an MDI form, where i load multiple child forms from a dll i create, using reflection and late binding The child forms have multiple radio...
6
by: =?Utf-8?B?L2Rldi9udWxs?= | last post by:
Hello, i am using visual studio 2003 enterprise architect version. I am making apps for the .Net framework 1.1. While testing an interface, i discovered something strange. In this application...
3
by: jubergolandaj | last post by:
I am working on Outlook Addin developed in C# and VS-2008. In this we are having our own custom form .oft On this form we have our custom “Send” button on click event of it our processing continues....
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.