Is there a way I can cancel a dispose from within the Dispose method, in other words NOT dispose A when A.Dispose() is called.
Update I didn't explain well, 'cos I couldn't think of a way to put it nicely. What I have is a class that displays a progress bar (marquee) in a popup window that runs in a separate thread. When the progress popup is created, a controller-like disposable object is returned, so we can do something like this:
using (var progress = Dialogs.ShowProgress("Please wait..."))
{
// do lots of stuff here
progress.UpdateStatus("Please wait some more...");
// do more stuff
}
when the using block exits, the progress window is closed and destroyed.
Now I have situations where things that happen within this block also create a progress window and instead of returning a new object and creating a new window, I wanted to return the object created by the first instance, and only destroy it once the first instance disposes.
Update
Ok, what I did was to create a new IDisposable object with each Dialogs.ShowProgress() call, and attached the original controller object to it. These objects get disposed of whenever they're done, and the controller only gets disposed when it's the only object left to dispose.
Disposemethod, which is a convention (widely used across the .NET Framework, but not a language thing, just a convention), with a finalizer (which has a different syntax), and still you can't cancel a finalizer (which makes no sense)... the way to "cancel"Disposeis just... not callingDispose. - Jcl