Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / VS Tools for Office / May 2006

Tip: Looking for answers? Try searching our database.

VSTO 2005 problems

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
magne - 22 May 2006 10:58 GMT
Using VS 2005 (Team Edition for Software Architects) and VSTO 2005 (and
Office2003).

Creating an Excel Workbook project.
Adding code in ThisWorkbook.ThisWorkbook_Startup which adds a new
msoControlPopup to an existing menu.
The code also sets up a click event handler, "myMenuItem.Click += new
_CommandBarButtonEvents_ClickEventHandler(ClickHandler);"

The handler as:
private void ClickHandler(CommandBarButton Ctrl, ref bool CancelDefault)
{
   MessageBox.Show("My menu item was clicked");
}

This works fine when I start debugging and clicks the menu item (MessageBox
shows up), but when I repeat the click without restarting the debugging, the
messagebox does not show up.
Anyone knows why ?
magne - 22 May 2006 15:37 GMT
Additional info:
If I add "System.GC.Collect();" after the "event wiring"
(i.e. after "myMenuItem.Click += new
_CommandBarButtonEvents_ClickEventHandler(ClickHandler);", it seems like it
is working every time.
Someone able to explain why ???
Anyway, I still feel that "something is wrong" !

> Using VS 2005 (Team Edition for Software Architects) and VSTO 2005 (and
> Office2003).
[quoted text clipped - 15 lines]
> debugging, the messagebox does not show up.
> Anyone knows why ?
Harry Miller [MSFT] - 22 May 2006 18:15 GMT
Make sure you declare the menu items at the class level, not in a method, or
they will be garbage-collected after the method goes out of scope. There's a
blog post about that here:
http://blogs.msdn.com/vsto/archive/2004/01/29/64449.aspx

Signature

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

> Additional info:
> If I add "System.GC.Collect();" after the "event wiring"
[quoted text clipped - 23 lines]
> > debugging, the messagebox does not show up.
> > Anyone knows why ?
magne - 22 May 2006 20:05 GMT
Thanks, of course you are right.
Actually I declared at instance variable, but unfortunately the wrong
variable, but are you able to explain to me why it works when I did an
explicit garbage collection (which of course did not collect the menu
variable, too early for that) ?

> Make sure you declare the menu items at the class level, not in a method,
> or
[quoted text clipped - 33 lines]
>> > debugging, the messagebox does not show up.
>> > Anyone knows why ?
Harry Miller [MSFT] - 23 May 2006 16:26 GMT
No, I can't explain it. That had me wondering, too.

Signature

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

> Thanks, of course you are right.
> Actually I declared at instance variable, but unfortunately the wrong
[quoted text clipped - 39 lines]
> >> > debugging, the messagebox does not show up.
> >> > Anyone knows why ?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.