Re: Class Dispose
From: Tamir Khason (tamir-NOSPAM_at_tcon-NOSPAM.co.il)
Date: 09/27/04
- Next message: Joe Mayo: "Re: red cells in DataGrid"
- Previous message: Alex K.: "red cells in DataGrid"
- In reply to: Nicholas Paldino [.NET/C# MVP]: "Re: Class Dispose"
- Next in thread: Chris Lyon [MSFT]: "Re: Class Dispose"
- Reply: Chris Lyon [MSFT]: "Re: Class Dispose"
- Reply: Scott Allen: "Re: Class Dispose"
- Reply: Richard Blewett [DevelopMentor]: "Re: Class Dispose"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 27 Sep 2004 19:26:34 +0200
Thjis still does not work:
public class Foo: IDisposable
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if(disposing)
{
StopDoingThis()
}
}
~Foo()
{
Dispose(false);
}
public Foo()
{
StartDoingThis();
}
StartDoingThis()
{
Console.Write("Stop");
}
StartDoingThis()
{
Console.Write("Start");
}
}
public class Caller
{
public Caller()
{
Foo f = new Foo();
}
}
While running Caller it appears:
"Start" and the program exits. How to make it writing "Stop". What I'm doing
wrong?
Thank you
"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:efAMSNLpEHA.3252@TK2MSFTNGP14.phx.gbl...
> Tamir,
>
> You can execute code in the finalizer. However, that code doesn't run
> when there are no more references to it. Rather, it runs when the object
> is garbage collected. If you have code that depends on being called when
> the object is disposed of, then you should implement the IDisposable
> interface.
>
> Check out the section of the .NET framework general reference titled
> "Implementing Finalize and Dispose to Clean Up Unmanaged Resources",
> located at (watch for line wrap):
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconFinalizeDispose.asp
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mvp@spam.guard.caspershouse.com
>
> "Tamir Khason" <tamir-NOSPAM@tcon-NOSPAM.co.il> wrote in message
> news:uNwSUGLpEHA.132@TK2MSFTNGP14.phx.gbl...
>>I have a class
>> public class Foo
>> {
>> public Foo()
>> {
>> DoSomething()
>> }
>> }
>>
>> I want to be able to do something else while the class enters GC - no
>> more references or the runner exites [without doing anything in runner
>> code] (as it was
>> ~Foo()
>> {
>> StopDoingSomething();
>> }
>> does not works.
>>
>> Please advice
>>
>> --
>> Tamir Khason
>> You want dot.NET? Just ask:
>> "Please, www.dotnet.us "
>>
>>
>
>
- Next message: Joe Mayo: "Re: red cells in DataGrid"
- Previous message: Alex K.: "red cells in DataGrid"
- In reply to: Nicholas Paldino [.NET/C# MVP]: "Re: Class Dispose"
- Next in thread: Chris Lyon [MSFT]: "Re: Class Dispose"
- Reply: Chris Lyon [MSFT]: "Re: Class Dispose"
- Reply: Scott Allen: "Re: Class Dispose"
- Reply: Richard Blewett [DevelopMentor]: "Re: Class Dispose"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|