473,396 Members | 1,886 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,396 software developers and data experts.

BUG in VB .NET 2003?

Hi to All,

I found the following issue, is this a bug?

Create a new project and, in the main form, add a listbox with a few sample
items. In the DoubleClick event of the listbox, add:

Me.Dispose()

Then run the project, double click on an item in the listbox to close the
window and then an Exception occurs.

What is the problem? I would like to close the form by double clicking on
the listbox...
Thank you,

Andy

Nov 20 '05 #1
14 3152
what's the exception?
"Andy" <no****@nospam.com> wrote in message
news:9F**********************@news2.tin.it...
Hi to All,

I found the following issue, is this a bug?

Create a new project and, in the main form, add a listbox with a few sample items. In the DoubleClick event of the listbox, add:

Me.Dispose()

Then run the project, double click on an item in the listbox to close the
window and then an Exception occurs.

What is the problem? I would like to close the form by double clicking on
the listbox...
Thank you,

Andy

Nov 20 '05 #2
In article <9F**********************@news2.tin.it>, no****@nospam.com
says...
What is the problem? I would like to close the form by double clicking on
the listbox...


Try Me.Close().

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #3
Cor
Hi Andy,
You are not closing it, you are killing it, look at the message from Patrick
Cor
Nov 20 '05 #4
Not a bug. Do not Dispose() in a click event. I am not real Windows Forms
savvy, but there is a way to close the form. You can Dispose() afterward,
but you have to make sure there is a Dispose() method coded for the class
you are disposing. Not sure if a form class has a Dispose() method without
adding IDisposable. Either way, you do not want to Dispose() the object in
the object.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Andy" <no****@nospam.com> wrote in message
news:9F**********************@news2.tin.it...
Hi to All,

I found the following issue, is this a bug?

Create a new project and, in the main form, add a listbox with a few sample items. In the DoubleClick event of the listbox, add:

Me.Dispose()

Then run the project, double click on an item in the listbox to close the
window and then an Exception occurs.

What is the problem? I would like to close the form by double clicking on
the listbox...
Thank you,

Andy

Nov 20 '05 #5
Something like "Cannot access disposed object named "ListBox"

Andy
"steve" <as*@abc.com> ha scritto nel messaggio
news:vn************@corp.supernews.com...
what's the exception?


Nov 20 '05 #6
The same Exception happens also with "Me.Close()"...

Andy
"Patrick Steele [MVP]" <pa*****@mvps.org> ha scritto nel messaggio
news:MP************************@msnews.microsoft.c om...
In article <9F**********************@news2.tin.it>, no****@nospam.com
says...
What is the problem? I would like to close the form by double clicking on the listbox...


Try Me.Close().


Nov 20 '05 #7
But I need to close (unload) the form from a double click event...

I searched with google and, strangely, in the first version of VB6 there was
a bug: if you tried to unload the form from a listbox's doubleclick event, a
GPF occurred. This was solved in later SP. What coincidence!

Andy

"msnews.microsoft.com" <No************@comcast.netNoSpamM> ha scritto nel
messaggio news:#G**************@tk2msftngp13.phx.gbl...
Not a bug. Do not Dispose() in a click event. I am not real Windows Forms
savvy, but there is a way to close the form. You can Dispose() afterward,
but you have to make sure there is a Dispose() method coded for the class
you are disposing. Not sure if a form class has a Dispose() method without
adding IDisposable. Either way, you do not want to Dispose() the object in
the object.


Nov 20 '05 #8
The point I am getting at is Dispose() is not the proper way to destroy an
object from inside the object. I would aim for close, but you are stating
you are getting the same message there. I do not understand the need to
close from doubleclick rather than set up a close button, but each app is
different.

This causes no problems for me in VS.NET 2003:

Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) _
Handles ListBox1.DoubleClick
Try
Me.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
'Finally
' MessageBox.Show("In Finally")
End Try
End Sub

unless I uncomment the Finally. This makes sense, as I have closed the form
by this point in time. I cannot run through debug on this machine, as I need
to catch someone to get permissions (aaarrrggghhhh!!!).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Andy" <no****@nospam.com> wrote in message
news:fW**********************@news2.tin.it...
But I need to close (unload) the form from a double click event...

I searched with google and, strangely, in the first version of VB6 there was a bug: if you tried to unload the form from a listbox's doubleclick event, a GPF occurred. This was solved in later SP. What coincidence!

Andy

"msnews.microsoft.com" <No************@comcast.netNoSpamM> ha scritto nel
messaggio news:#G**************@tk2msftngp13.phx.gbl...
Not a bug. Do not Dispose() in a click event. I am not real Windows Forms savvy, but there is a way to close the form. You can Dispose() afterward, but you have to make sure there is a Dispose() method coded for the class you are disposing. Not sure if a form class has a Dispose() method without adding IDisposable. Either way, you do not want to Dispose() the object in the object.


Nov 20 '05 #9
Try adding

Application.DoEvents before the close method...

I do'nt know if it will work, but dispose is for garbage collection, and not
the right way to shut down a window. Close calls dispose through Finalize I
believe.
"Andy" <no****@nospam.com> wrote in message
news:QT**********************@news2.tin.it...
The same Exception happens also with "Me.Close()"...

Andy
"Patrick Steele [MVP]" <pa*****@mvps.org> ha scritto nel messaggio
news:MP************************@msnews.microsoft.c om...
In article <9F**********************@news2.tin.it>, no****@nospam.com
says...
What is the problem? I would like to close the form by double clicking on the listbox...


Try Me.Close().


Nov 20 '05 #10
"CJ Taylor" <no****@blowgoats.com> ha scritto nel messaggio
news:vn************@corp.supernews.com...
Try adding

Application.DoEvents before the close method...

I do'nt know if it will work, but dispose is for garbage collection, and not the right way to shut down a window. Close calls dispose through Finalize I believe.


So, what is the best method to "unload" a form? Me.Close() or Me.Dispose()
or what else? In VB6 there was Unload Me...
Thanks,

Andy


Nov 20 '05 #11
Andy wrote:
Hi to All,

I found the following issue, is this a bug?

Create a new project and, in the main form, add a listbox with a few sample
items. In the DoubleClick event of the listbox, add:

Me.Dispose()

Then run the project, double click on an item in the listbox to close the
window and then an Exception occurs.

What is the problem? I would like to close the form by double clicking on
the listbox...
Thank you,

Andy


I have a guess at what's happening, and a possibly workaround.

I think what's happening is that when your DoubleClick handler is
executing, the call stack has the context of the ListBox's event
handler, which is busy looping through the Multicastdelegate object that
holds the list of DoubleClick events. You call the Close() or Dispose()
method on the Form, which in turn disposes the ListBox control.

When your event handler returns, it goes back to the ListBox control's
code that's looping through events. But since that object has been
disposed - bang... an exception. My guess is that this situation is
explicitly handled in a button's click event handler, since that's the
way Forms are normally closed.

If this is what's happening, then I'd agree that it's a bug, and should
be fixed by MS.

However, in the meantime you can use the following code to get the
Close() method to be called after you return from your DoubleClick event
handler (watch for word wrap):

Public Class Form1
Inherits System.Windows.Forms.Form

Delegate Sub CloseDelegate() ' declare a delegate type that
matches the Close() method

'
' whatever else you need in your class
'

Private Sub ListBox1_DoubleClick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.DoubleClick

' invoke the Close() method through an async delegate
Me.BeginInvoke(CType(AddressOf Me.Close, CloseDelegate))
End Sub
End Class

This calls the Close() method() through an async delegate, so it'll be
called at sometime after your call to BeginInvoke(). One thing to be
aware of is that I'm not sure if this is bullet-proof. It's not clear
to me that this will always complete all ListBox events before invoking
your async delegate.

To make that kind of guarantee would require a more complex set of
safeguards, probably involving timers, locks, and/or hooking the event
chain higher up the class hierarchy.

--
mikeb
Nov 20 '05 #12
"Andy" <no****@nospam.com> scripsit:
Create a new project and, in the main form, add a listbox with a few sample
items. In the DoubleClick event of the listbox, add:

Me.Dispose()

Then run the project, double click on an item in the listbox to close the
window and then an Exception occurs.


Doesn't 'Me.Close()' close the form?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #13
"Andy" <no****@nospam.com> schrieb
"CJ Taylor" <no****@blowgoats.com> ha scritto nel messaggio
news:vn************@corp.supernews.com...
Try adding

Application.DoEvents before the close method...

I do'nt know if it will work, but dispose is for garbage
collection, and

not
the right way to shut down a window. Close calls dispose through
Finalize

I
believe.


So, what is the best method to "unload" a form? Me.Close() or
Me.Dispose() or what else? In VB6 there was Unload Me...
Thanks,


Use Me.Close

As already said, Dispose kills the form and this also means that no closing
or closed events are fired.
--
Armin

Nov 20 '05 #14
Hi,

If you are seeing an exception from Me.Close, something else is cause it.
This is the correct way to close a form.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
Nov 20 '05 #15

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

Similar topics

1
by: David Lee | last post by:
Need some help bad here. Am using VB.Net Standard 2003 supplied for a class and I need to install Msde and the sample databases to work on homework. Following the documentation I can download...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
6
by: David Waz... | last post by:
Moved an app from W/2000 Asp V1.0 to W/2003, VS/2003, ASPV 1.1 Page runs a long job, uploading 2 large fixed length files (300,000 rows) into SQL database. A process is run against the data,...
22
by: EP | last post by:
When running my asp.net hosting service (asp.net without IIS), on server 2003 with IIS not installed, I get the following when trying to process a request. "System.DllNotFoundException: Unable to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.