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

Dispose called twice

Hi.
I put a message box in the form designer, Dispose method.
Clicking the form close (X) button, i noticed that the message,
appears twice.
My code does not call Dispose.
What is happening here?
Thanks.
Sharon.
Nov 19 '05 #1
2 1418
Sharon:
This is an ASP.Net newsgroup, you might be better off asking in
microsoft.public.dotnet.framework.windowsforms

aside from that, I can tell you that Dipose must be implemented in such a
way that multiple calls to it aren't going to cause any problem, typically
this is achieved by using a private field named "isDisposed" or something
which is set to "false" and when Dispose() is called, something like this
happens:

if isDiposed = false then
..clean up resources
isDisposed = true
end if
therefore nothing bad can happen from it being called multiple times. I
figure it's doing so because a number of events are internally firing which
are each causing the Dispose method to be called...better to be safe than
sorry.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/index.aspx - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Sharon" <ta*******@void.null> wrote in message
news:O4**************@TK2MSFTNGP15.phx.gbl...
Hi.
I put a message box in the form designer, Dispose method.
Clicking the form close (X) button, i noticed that the message,
appears twice.
My code does not call Dispose.
What is happening here?
Thanks.
Sharon.

Nov 19 '05 #2
Thanks Karl for your reply.
This thread was opened by mistake, sorry.
It was meant for microsoft.public.dotnet.languages.csharp.
Anyway, what i want to know is the reason why dispose is called twice.
Regards.
Sharon.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:ud**************@TK2MSFTNGP09.phx.gbl...
Sharon:
This is an ASP.Net newsgroup, you might be better off asking in
microsoft.public.dotnet.framework.windowsforms

aside from that, I can tell you that Dipose must be implemented in such a
way that multiple calls to it aren't going to cause any problem, typically
this is achieved by using a private field named "isDisposed" or something
which is set to "false" and when Dispose() is called, something like this
happens:

if isDiposed = false then
..clean up resources
isDisposed = true
end if
therefore nothing bad can happen from it being called multiple times. I
figure it's doing so because a number of events are internally firing which are each causing the Dispose method to be called...better to be safe than
sorry.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/index.aspx - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Sharon" <ta*******@void.null> wrote in message
news:O4**************@TK2MSFTNGP15.phx.gbl...
Hi.
I put a message box in the form designer, Dispose method.
Clicking the form close (X) button, i noticed that the message,
appears twice.
My code does not call Dispose.
What is happening here?
Thanks.
Sharon.


Nov 19 '05 #3

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

Similar topics

3
by: faktujaa | last post by:
Hi All, A small confusion. I have defined a connection class that has System.Data.IDbConnection as a member variable and implements IDisposable interface. I have implemented Dispose method to call...
4
by: RiteshDotNet | last post by:
..net Frame work 1. Dispose Method what it does ? A. who its call / when it calls ? B. Is it fire automatically ? c. When dispose method is call what it does ? D. Release a Object from memory or...
11
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our...
16
by: Daniel Mori | last post by:
If an object implements the IDisposable interface (regardless if its a framework object or a user object), should I always dispose of that object out of principle?
4
by: Sharon | last post by:
Hi. I put a message box in the form designer, Dispose method. Clicking the form close (X) button, i noticed that the message, appears twice. My code does not call Dispose. What is happening...
3
by: Maxim | last post by:
Hi! According to documenation, if we need to release some umanaged resources manually, we need to implement IDisposable interface with single Dispose method. I am just wondering, what will...
2
by: KSC | last post by:
Hello, I have used a thread timer as in the documentation on MSDN in my VB.NET application. Using System.Threading.Interlocked.Increment I increment the counter to a certain point, perform an...
156
by: Dennis | last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose method based on advice from this newsgroup. However, I'm not sure how to dispose of the following object that was created...
71
by: active | last post by:
In the main program I check to see if a certain form has been disposed. Does it make sense in that form's FormClosed event to do: Me.Dispose to make sure it is disposed the next time I check. Or...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.