473,799 Members | 2,997 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# .NET 2.0 this.Close() and ToolStripDrropD own Menus

OK, I have a form with a menu and a tool bar. In the Menu I have a File
menu that contains a "Exit" item. When I click this Exit item. I have an
event wired to:

mnuFile.DropDow n.ItemClicked

In that event I check the:

event handler ...
if ( e.ClickedItem.T ag != null )
ProcessMenu( e.ClickedItem.T ag.ToString() )
System.Diagnost ics.Debug.Write Line( "Done" );

I do this because I have 1 function for all my menus on this screen. In
this function I have a switch statement:

switch ( tag )
{
....
case "Exit":
this.Close();
break;
....
}

This function returns up to the event handler successfully processes my
WriteLine statement, and then procedures to crash with:

{"Cannot access a disposed object.\r\nObje ct name:
'ToolStripDropD ownMenu'."}

Why am I getting this error. There is no code after this and my code in my
Dispose processes correctly also. In stepping through the code the Dispose
happens before my this.Close() returns anyway, so I know all that is
functioning correctly. My thought on what is happening here is that at this
point after the event handler is done the ToolStrip is trying to hide the
drop down control, but since my form is already disposed of the ToolStrip is
causing an error internally. I think this because I can view the drop down
menu while stepping though my code. My thought is that after I clicked that
item the drop down should have disappeared on its own. Well anyway this
feels like a bug to me in the ToolStrip control, and I think I found a work
around. In my event I added this code to the beginning:

((ToolStripDrop Down)sender).Hi de();

By doing this I know longer crash when I close my application.

Eric Renken

Dec 7 '05 #1
5 2725
Sorry about some of the bad grammar up front. Was trying to get this out
way to fast.

Eric Renken

"Eric Renken" <Er*********@ne wsgroup.nospam> wrote in message
news:Oe******** ********@TK2MSF TNGP15.phx.gbl. ..
OK, I have a form with a menu and a tool bar. In the Menu I have a File
menu that contains a "Exit" item. When I click this Exit item. I have an
event wired to:

mnuFile.DropDow n.ItemClicked

In that event I check the:

event handler ...
if ( e.ClickedItem.T ag != null )
ProcessMenu( e.ClickedItem.T ag.ToString() )
System.Diagnost ics.Debug.Write Line( "Done" );

I do this because I have 1 function for all my menus on this screen. In
this function I have a switch statement:

switch ( tag )
{
...
case "Exit":
this.Close();
break;
...
}

This function returns up to the event handler successfully processes my
WriteLine statement, and then procedures to crash with:

{"Cannot access a disposed object.\r\nObje ct name:
'ToolStripDropD ownMenu'."}

Why am I getting this error. There is no code after this and my code in
my Dispose processes correctly also. In stepping through the code the
Dispose happens before my this.Close() returns anyway, so I know all that
is functioning correctly. My thought on what is happening here is that at
this point after the event handler is done the ToolStrip is trying to hide
the drop down control, but since my form is already disposed of the
ToolStrip is causing an error internally. I think this because I can view
the drop down menu while stepping though my code. My thought is that
after I clicked that item the drop down should have disappeared on its
own. Well anyway this feels like a bug to me in the ToolStrip control,
and I think I found a work around. In my event I added this code to the
beginning:

((ToolStripDrop Down)sender).Hi de();

By doing this I know longer crash when I close my application.

Eric Renken

Dec 7 '05 #2
Hi Eric,

Thanks for your post.

Currently, for this issue, can you provide a little sample project to
demonstrate the problem? Then we can understand the problem context much
better. This is because the currently information you provided is not
enough for us to reproduce the problem.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 8 '05 #3
Hi Eric,

Thanks for your feedback.

Yes, with your sample project, I can reproduce out this problem.

I think you are right. If we enable first chance exception in VS2005 after
setting up the symbol correctly. We will get the following call stack
because of the ObjectDisposedE xception:
System.Windows. Forms.dll!Syste m.Windows.Forms .Control.Create Handle() Line
5581 + 0x2a bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.CreateHandl e
() Line 1143 C#
System.Windows. Forms.dll!Syste m.Windows.Forms .Control.Handle .get() Line
2743 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.ReparentToD r
opDownOwnerWind ow() Line 1657 + 0xb bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.SetVisibleC o
re(bool visible = false) Line 1913 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.OnItemClick e
d(System.Window s.Forms.ToolStr ipItemClickedEv entArgs e =
{System.Windows .Forms.ToolStri pItemClickedEve ntArgs}) Line 1358 + 0x19
bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStrip.Hand leItemClick(Sys t
em.Windows.Form s.ToolStripItem dismissingItem = {Close}) Line 2582 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripItem. HandleClick(Sys t
em.EventArgs e = {System.EventAr gs}) Line 2769 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripItem. HandleMouseUp(S y
stem.Windows.Fo rms.MouseEventA rgs e = {X = 30 Y = 15 Button = Left}) Line
2920 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripItem. FireEventIntera c
tive(System.Eve ntArgs e, System.Windows. Forms.ToolStrip ItemEventType met)
Line 2626 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripItem. FireEvent(Syste m
.EventArgs e, System.Windows. Forms.ToolStrip ItemEventType met) Line 2607 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStrip.OnMo useUp(System.Wi n
dows.Forms.Mous eEventArgs mea) Line 3531 + 0xd bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.OnMouseUp(S y
stem.Windows.Fo rms.MouseEventA rgs mea = {X = 30 Y = 17 Button = Left}) Line
1439 C#
System.Windows. Forms.dll!Syste m.Windows.Forms .Control.WmMous eUp(ref
System.Windows. Forms.Message m, System.Windows. Forms.MouseButt ons button,
int clicks) Line 13032 + 0x5e bytes C#
System.Windows. Forms.dll!Syste m.Windows.Forms .Control.WndPro c(ref
System.Windows. Forms.Message m) Line 13762 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ScrollableCont rol.WndProc(ref
System.Windows. Forms.Message m) Line 1491 C#
System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStrip.WndP roc(ref
System.Windows. Forms.Message m = {msg=0x202 (WM_LBUTTONUP) hwnd=0x109c0
wparam=0x0 lparam=0x11001e result=0x0}) Line 4627 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.WndProc(ref
System.Windows. Forms.Message m) Line 2112 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .Control.Contro lNativeWindow.O n
Message(ref System.Windows. Forms.Message m) Line 14049 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .Control.Contro lNativeWindow.W n
dProc(ref System.Windows. Forms.Message m) Line 14104 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .NativeWindow.D ebuggableCallba c
k(System.IntPtr hWnd, int msg = 514, System.IntPtr wparam, System.IntPtr
lparam) Line 777 + 0xa bytes C#
[Native to Managed Transition]
[Managed to Native Transition]

System.Windows. Forms.dll!Syste m.Windows.Forms .Application.Co mponentManager. S
ystem.Windows.F orms.UnsafeNati veMethods.IMsoC omponentManager .FPushMessageLo o
p(int dwComponentID, int reason = -1, int pvLoopData = 0) Line 2106 + 0x8
bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .Application.Th readContext.Run M
essageLoopInner (int reason = -1, System.Windows. Forms.Applicati onContext
context = {System.Windows .Forms.Applicat ionContext}) Line 3359 + 0x1b bytes
C#

System.Windows. Forms.dll!Syste m.Windows.Forms .Application.Th readContext.Run M
essageLoop(int reason, System.Windows. Forms.Applicati onContext context)
Line 3243 + 0xa bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .Application.Ru n(System.Window s
.Forms.Form mainForm) Line 1466 C#
MenuCrashSample .exe!MenuCrashS ample.Program.M ain() Line 17 + 0x1a bytes C#


With Reflector, we will find the following code in
System.Windows. Forms.Control.C reateHandle() method:

protected virtual void CreateHandle()
{
IntPtr ptr1 = IntPtr.Zero;
if (this.GetState( 0x800))
{
throw new ObjectDisposedE xception(base.G etType().Name);
}
.....
}

Then by using Reflector to view Control.Dispose method, we will see the
following code in finally clause:
finally
{
this.ResumeLayo ut(false);
this.SetState(0 x1000, false);
this.SetState(0 x800, true);
}

So, Control.Dispose () method turn on 0x800 flag, which causes
ObjectDisposedE xception in System.Windows. Forms.Control.C reateHandle()
method.

Currently, I think your workaround of using mnuFile.DropDow n.Hide() should
be a good one. Also, you may submit a bug request to our product team in
the link below:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 12 '05 #4
Jeffery,

Thanks for looking at this. I have submitted the bug to that URL you
listed. Along with the sample project.

Thanks again,

Eric Renken

""Jeffrey Tan[MSFT]"" <v-*****@online.mi crosoft.com> wrote in message
news:N7******** ******@TK2MSFTN GXA02.phx.gbl.. .
Hi Eric,

Thanks for your feedback.

Yes, with your sample project, I can reproduce out this problem.

I think you are right. If we enable first chance exception in VS2005 after
setting up the symbol correctly. We will get the following call stack
because of the ObjectDisposedE xception:
System.Windows. Forms.dll!Syste m.Windows.Forms .Control.Create Handle() Line
5581 + 0x2a bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.CreateHandl e
() Line 1143 C#
System.Windows. Forms.dll!Syste m.Windows.Forms .Control.Handle .get() Line
2743 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.ReparentToD r
opDownOwnerWind ow() Line 1657 + 0xb bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.SetVisibleC o
re(bool visible = false) Line 1913 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.OnItemClick e
d(System.Window s.Forms.ToolStr ipItemClickedEv entArgs e =
{System.Windows .Forms.ToolStri pItemClickedEve ntArgs}) Line 1358 + 0x19
bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStrip.Hand leItemClick(Sys t
em.Windows.Form s.ToolStripItem dismissingItem = {Close}) Line 2582 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripItem. HandleClick(Sys t
em.EventArgs e = {System.EventAr gs}) Line 2769 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripItem. HandleMouseUp(S y
stem.Windows.Fo rms.MouseEventA rgs e = {X = 30 Y = 15 Button = Left}) Line
2920 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripItem. FireEventIntera c
tive(System.Eve ntArgs e, System.Windows. Forms.ToolStrip ItemEventType met)
Line 2626 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripItem. FireEvent(Syste m
EventArgs e, System.Windows. Forms.ToolStrip ItemEventType met) Line 2607 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStrip.OnMo useUp(System.Wi n
dows.Forms.Mous eEventArgs mea) Line 3531 + 0xd bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.OnMouseUp(S y
stem.Windows.Fo rms.MouseEventA rgs mea = {X = 30 Y = 17 Button = Left})
Line
1439 C#
System.Windows. Forms.dll!Syste m.Windows.Forms .Control.WmMous eUp(ref
System.Windows. Forms.Message m, System.Windows. Forms.MouseButt ons button,
int clicks) Line 13032 + 0x5e bytes C#
System.Windows. Forms.dll!Syste m.Windows.Forms .Control.WndPro c(ref
System.Windows. Forms.Message m) Line 13762 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ScrollableCont rol.WndProc(ref
System.Windows. Forms.Message m) Line 1491 C#
System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStrip.WndP roc(ref
System.Windows. Forms.Message m = {msg=0x202 (WM_LBUTTONUP) hwnd=0x109c0
wparam=0x0 lparam=0x11001e result=0x0}) Line 4627 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .ToolStripDropD own.WndProc(ref
System.Windows. Forms.Message m) Line 2112 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .Control.Contro lNativeWindow.O n
Message(ref System.Windows. Forms.Message m) Line 14049 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .Control.Contro lNativeWindow.W n
dProc(ref System.Windows. Forms.Message m) Line 14104 C#

System.Windows. Forms.dll!Syste m.Windows.Forms .NativeWindow.D ebuggableCallba c
k(System.IntPtr hWnd, int msg = 514, System.IntPtr wparam, System.IntPtr
lparam) Line 777 + 0xa bytes C#
[Native to Managed Transition]
[Managed to Native Transition]

System.Windows. Forms.dll!Syste m.Windows.Forms .Application.Co mponentManager. S
ystem.Windows.F orms.UnsafeNati veMethods.IMsoC omponentManager .FPushMessageLo o
p(int dwComponentID, int reason = -1, int pvLoopData = 0) Line 2106 + 0x8
bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .Application.Th readContext.Run M
essageLoopInner (int reason = -1, System.Windows. Forms.Applicati onContext
context = {System.Windows .Forms.Applicat ionContext}) Line 3359 + 0x1b
bytes
C#

System.Windows. Forms.dll!Syste m.Windows.Forms .Application.Th readContext.Run M
essageLoop(int reason, System.Windows. Forms.Applicati onContext context)
Line 3243 + 0xa bytes C#

System.Windows. Forms.dll!Syste m.Windows.Forms .Application.Ru n(System.Window s
Forms.Form mainForm) Line 1466 C#
MenuCrashSample .exe!MenuCrashS ample.Program.M ain() Line 17 + 0x1a bytes
C#


With Reflector, we will find the following code in
System.Windows. Forms.Control.C reateHandle() method:

protected virtual void CreateHandle()
{
IntPtr ptr1 = IntPtr.Zero;
if (this.GetState( 0x800))
{
throw new ObjectDisposedE xception(base.G etType().Name);
}
....
}

Then by using Reflector to view Control.Dispose method, we will see the
following code in finally clause:
finally
{
this.ResumeLayo ut(false);
this.SetState(0 x1000, false);
this.SetState(0 x800, true);
}

So, Control.Dispose () method turn on 0x800 flag, which causes
ObjectDisposedE xception in System.Windows. Forms.Control.C reateHandle()
method.

Currently, I think your workaround of using mnuFile.DropDow n.Hide() should
be a good one. Also, you may submit a bug request to our product team in
the link below:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 12 '05 #5
Ok. If you need further help, please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
25033
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or less complex technical calculations, several input variables. I would like to equipp the starting panel with the usual New, Open, Save, Save As, Close etc. menus (like in Excel, or Word, etc.) What is the best way to accomplish Save, or Save As?...
9
2160
by: flarkblark | last post by:
I recently had the displeasure of looking at the code required to implement the pop-up menus used in a pulldown menu system for a webpage. The sheer amount of Javascript required was amazing and frankly revolting. It is as though the software "engineers" have been thrown out and replaced with "programmers". That is to say, it is a sophomoric hack job, a hideous kludge.
19
2864
by: chart43 | last post by:
I have question about the technique for css dropdown menus described in http://www.alistapart.com/articles/horizdropdowns/. Based on an html list, it has a few items in a 1st order list and further 2nd order lists that appear to the right when hovering over items in the 1st order. Anyone figured how to modify to go to n order greater than 2? Bit tricky I found. I could get the other orders but they all appeared when hovering over the 1st...
2
2418
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta http-equiv="Content-Type" content="text/html;
4
1501
by: Alex | last post by:
Is it possible to put a menu on a form Window or ary there any controls that I could use to simulate a menu? Thanks Alex
0
264
by: Keith | last post by:
When merging two menus, it doesn't actually merge their sub menus and menu items It only displays two menus on one forms instead of merging two sub menus into one if they have sam menu text e.g. if menu1 has submenu File which has New,Open item and menu2 has submenu File which has Save After merging menu2 into menu1, it displays two sub menu
4
1458
by: Bratislav Jevtic | last post by:
hi, we developed an application having server-side menus. however, I'm interested for: 1. some nice client side drop down menus. ideal solution would be something like windows menus in desktop applications (menus, submenus, check box items, etc) but working in JavaScript. 2. if I select something on client side menu (JavaScript), how to invoke
5
1986
by: Steve Le Monnier | last post by:
I've just noticed that the menu items available in Visual Studio 2005 for the Debug and Build menus differ significantly when compared to the menu items in Visual Studio 2003. On my C# installation I don't have build solution, rebuild solution, Step into, Step out, or the Exceptions options on my menu Does anybody know why these important tools are missing from the menu structure?
5
2388
by: Cylix | last post by:
this.menus = { root: new Array };
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10485
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.