I have Overloaded the Dispose method of System.Windows.Forms.Form Class in which I have written some extra code which I need to execute when object of Form Disposes. But when I create the object of Form in 'Using' statement, the 'End Using, statement do not execute my overloaded Dispose method. What should I do?
Dispose method in Using Statement.
Page 1 of 113 Replies - 933 Views - Last Post: 16 February 2012 - 03:19 PM
Topic Sponsor:
Replies To: Dispose method in Using Statement.
#2
Re: Dispose method in Using Statement.
Posted 08 February 2012 - 06:52 AM
If I'm not mistaken, using statement automatically disposes of any objects it has before the end, that is it calls the dispose method of that particular object, so you might try a with statement instead. That is the only reason I can see that you would have any issue getting around to your overloaded dispose. Why are you using the forms dispose method? Also might I see your code?
#3
Re: Dispose method in Using Statement.
Posted 11 February 2012 - 05:34 AM
I am sending my code as an attachment. When I create a object of MyForm and call its Dispose method, the overloaded Dispose method gets called. But while using 'Using' statement to create the object of MyForm, the 'End Using' statement do not calls the overloaded Dispose method.
#4
Re: Dispose method in Using Statement.
Posted 11 February 2012 - 06:03 AM
I see no attachment. It's best if you post your code here.
#5
Re: Dispose method in Using Statement.
Posted 11 February 2012 - 09:02 AM
Read my post.
#6
Re: Dispose method in Using Statement.
Posted 11 February 2012 - 10:14 AM
What's wrong with the Form Closing event. You can dispose any object there. It might be a good idea to show us what your talking about - there might be a best practice thing we can advise on.
#7
Re: Dispose method in Using Statement.
Posted 12 February 2012 - 06:35 AM
Sorry, I didn't attach the code last time. Please see the code I have attached and reply.
Attached File(s)
-
WindowsApplication1.zip (59.2K)
Number of downloads: 11
#8
Re: Dispose method in Using Statement.
Posted 12 February 2012 - 06:40 AM
Please post your code in code tags like:

We are not interested in downloading attachment for security reasons.....
We are not interested in downloading attachment for security reasons.....
#9
Re: Dispose method in Using Statement.
Posted 15 February 2012 - 06:51 AM
Below is my code:-
Public Class MyForm
Inherits Form
Public Overloads Sub Dispose()
MyBase.Dispose()
MsgBox("Disposed")
End Sub
End Class
Dim form1 As New MyForm
form1.Dispose() 'This calls the overloaded Dispose Method and MsgBox get displayed.
Using myForm As New MyForm
myForm.Text = "CHILD_FORM"
myForm.ShowDialog()
End Using 'But this statement do not calls the overloaded Dispose Method and MsgBox do not get displayed.
#10
Re: Dispose method in Using Statement.
Posted 15 February 2012 - 10:25 AM
I'm not sure using statements call overloaded methods.
#11
Re: Dispose method in Using Statement.
Posted 16 February 2012 - 11:31 AM
Using statements do not call overloaded Dispose methods.
#12
Re: Dispose method in Using Statement.
Posted 16 February 2012 - 12:51 PM
Exactly why I was saying don't use a using method, especially if you're trying to call the dispose method, just call it. The using statement is for a little help managing your memory.
#13
Re: Dispose method in Using Statement.
Posted 16 February 2012 - 01:43 PM
Just for the sake of learning (since I am not much of an extension writer yet):
In order to be able to use the Using statement, would you be able to write some kind of code to alter IDisposable since that is what the Using statement refers to?
In order to be able to use the Using statement, would you be able to write some kind of code to alter IDisposable since that is what the Using statement refers to?
#14
Re: Dispose method in Using Statement.
Posted 16 February 2012 - 03:19 PM
You won't be able to use the using statement because you can't edit the disposable interface only inherit it, that being said you'll only be able to create your own class to inherit the interface and the dispose method and the using statement won't call that one. I could be wrong.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|