MDI - disposing of child windows after a period of inavtivity

  • Thread starter Thread starter Paul Aspinall
  • Start date Start date
P

Paul Aspinall

Hi
I have an MDI app....
All child MDI windows are non-updateable... however, the users may leave the
windows open... and there can be several of them.

I want to implement a system to dispose of MDI child windows after a period
of inactivity, in order to release resources and fire a garbage collect...

Does anyone have any views, or ideas on how to do this??

Thanks
 
Paul,

You would create the forms so that each form would have a timer that
would fire when the time expires. Every time you do an action on the form,
you would reset the timer and change the time elapsed (you would disable the
timer, then restart it).

Basically, when the timer fires, you would call Dispose on the form (the
timer will only fire when no action has taken place). This will take care
of the unmanaged resources the form was holding.

It might actually be a good idea to call GC.Collect. I used to think
that you should not call GC.Collect except in the most rare of cases, but it
appears that your situation is prime for calling a Collect. Check out Rico
Mariani's blog entry on the subject, located at (watch for line wrap):

http://blogs.msdn.com/ricom/archive/2004/11/29/271829.aspx

However, I would still generally say that you should not call GC.Collect
generally, unless your performance tests indicate you have a bottleneck
under the conditions specified in the blog entry.

Hope this helps.
 
You can use Deactivate event of the Child Form with a timer.

private void ChildForm_Deactivate(object sender, System.EventArgs e)

{

Timer t = new Timer();

t.Tick +=new EventHandler(t_Tick);

t.Interval = 2000; // for two seconds

t.Start();

}


protected void t_Tick(object sender , EventArgs e)

{

this.Dispose();

}



Hope this Helps
 
Thanks for the replies,

How can I tell if the form is the 'active' MDI child??
I don't want to shut the window, if it is the active MDI child...

Thanks
 
Back
Top