Alok
Wed Apr 21 22:55:25 CDT 2004
Hi Eric,
The piece of code really helped.
But what about second level controls. For instance, if i have a user
control, would i have to write this code in it's dispose method as well ??
TIA
"Eric Cadwell" <ecadwell@ns.insight.com> wrote in message
news:uwfrfP7JEHA.1392@TK2MSFTNGP09.phx.gbl...
> It's is my experience that you should call Dispose on anything and
> everything that implements IDisposable.
>
> Here's a sample function that I wrote that will call dispose on all
> non-public instance variables within a class. Call this from within the
> Form's Dispose method. This prevents you from having to explicitly list
all
> the calls inside Dispose.
>
> private void Disposer()
> {
> Type type = this.GetType();
> if (type != null)
> {
> foreach(FieldInfo fi in type.GetFields(BindingFlags.NonPublic |
> BindingFlags.Instance))
> {
> object field = fi.GetValue(this);
> if (field is IDisposable)
> {
> ((IDisposable)field).Dispose();
> Console.WriteLine("disposed field:" + fi.Name);
> }
> }
> }
> }
>
> HTH;
> Eric Cadwell
>
http://www.origincontrols.com
>
>
>