473,770 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
14 3172
"CJ Taylor" <no****@blowgoa ts.com> ha scritto nel messaggio
news:vn******** ****@corp.super news.com...
Try adding

Application.DoE vents 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 Multicastdelega te 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_Double Click(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles ListBox1.Double Click

' 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****@blowgoa ts.com> ha scritto nel messaggio
news:vn******** ****@corp.super news.com...
Try adding

Application.DoE vents 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
4860
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 sql2kdesksp3.exe and get the server running. I cannot then install the sample databases according to directions. Log file follows: 2:28:26 AM Wednesday, October 01, 2003: 12:28:26 AM Wednesday, October 01, 2003: Modified the sourceview node of...
0
6137
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 file as folows. I need help to resolve them ASAP: cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D " WIN32" /D "_W INDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /
6
2146
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, and altered flat-files produced. The job aborts at EXACTLY 105 seconds (1 min, 45 seconds) regardless of WHERE in the process we are - could be DB read, DB write, string manipulation - whatever.
22
3304
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 load DLL (aspnet_isapi.dll)." Of course the dll is able to be found, it's still in the framework directory and for grins I even put it in my service's local directory. This is apparantly server 2003 not allowing asp.net to be run if IIS was not...
0
9595
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
9432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10232
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
10059
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8891
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
7420
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
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
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
3
2822
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.