|
-
June 12th, 2007, 02:46 PM
#1
To destroy modeless form
I create a modeless form from my main modal dialog:
Code:
MForm form = new MForm;
form.Show();
How do I destroy this MForm completely? I need to destroy the form and everything on that form, to release memory and etc. I am trying to call
form.Dispose ();
but I am getting an error after that
-
June 12th, 2007, 02:49 PM
#2
Re: To destroy modeless form
i am new to this but i used
-
June 12th, 2007, 03:38 PM
#3
Re: To destroy modeless form
this.Close will close your application (by closing the main window).
form.Close() is what you're probably trying to say. it causes the form to be disposed.
if you're watching the memory window to see memory go down, it wont, this is because of the way .net operates. because you've disposed something doesnt mean its gone. there is a multi-tiered approach to garbage in .net so because you've disposed of an object doesnt mean that your application's memory usage is going to be lowered.
-
June 12th, 2007, 03:49 PM
#4
Re: To destroy modeless form
i used this.Close(); to close all my forms. should i be using form.Close(); instead?
-
June 12th, 2007, 04:45 PM
#5
Re: To destroy modeless form
he's wanting to close the form that he opened in his code sample, not to close down his whole application.
-
June 12th, 2007, 05:31 PM
#6
Re: To destroy modeless form
i tried to use form.Close(); and i got an error. this.Close(); works great for closing any form. it dosent close the whole application for me.
i also use the same code to open my form that nazgul27 used only i used my form names.
-
June 13th, 2007, 02:01 AM
#7
Re: To destroy modeless form
this.Close() works for the current window, the current context and you can use it when you have a modal dialog because you can not close it from the other dialogs. With form.Close() he ment closing one from from the other's context when you have modeless dialog. That means if you create a modeless dialog:
Code:
Form2 frm = new Form2();
frm.Show();
you can close it from another dialog ( which can get focus because we have modeless dialogs) : frm.Close().
Closing the whole application can be done with Application.Exit() or by closing the main form ( the one that is executed first in the thread from Program.cs):
Code:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Form1 in this case.
Last edited by creatorul; June 13th, 2007 at 02:03 AM.
Bogdan
If someone helped you then please Rate his post and mark the thread as Resolved
Please improve your messages appearance by using tags [ code] Place your code here [ /code]
-
June 13th, 2007, 07:15 AM
#8
Re: To destroy modeless form
Here is the problem. There is a webbrowser control on that modeless form, it navigates to a certain web site from time to time. Everytime it navigates the memory goes up. I described this problem in another topic though..
I don't know how to fix it rather than closing and opening the form again. But i don't know need to close it, i need the form to be destroyed totally. WebBrowser control also. and then reopen again.
there is a timer on that modeless form and here's what I noticed. If I just call:
then the timer is NOT destroyed, The application still call it and gets an exception after that.
I tried to call
Code:
form.cleanup();
form.Dispose ()
where i destroy the timer in "cleanup" function.
Anyway, this did not solve my problem. The memory is not freed. Seems like the only is to close the entire app and open it again.
Any ideas please
-
June 13th, 2007, 07:19 AM
#9
Re: To destroy modeless form
Remember that memory management in managed code is quite different.
Even if memory is "freed", it is not directly returned to the operating system. Therefore if you use tools like task manager you will get mis-leading information.
The only (neglecting 3rd party tools) way to see what is going on is to use Performance Monitor.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|