If(!Environment.HasShutdownStarted){
queue.Dispose();
}
Acording to the practicly nonexisting documentation this is where it should
be placed, in the finalizer to prevent calling functions on recycled
objects. What is weird is that this is the only thing NOT static in the
System.Environment class, wich makes the above example raise a compile-time
error. How is one to use the System.Environment.HasShutdownStarted???
Here is the full example (obviousley only for illustration purposes).
public class LikeThis: IDisposable{
public void Dispose(){
Dispose(true);
GC.SupressFinalize(this);
}
~LikeThis(){
Dispose(false);
}
protected virtual void Dispose(bool disposing){
// Dispose-time code
if(disposing){
queue.Dispose();
queue = null;
}
// Finalize-time code
CloseHandle();
If(!Environment.HasShutdownStarted){
queue.Dispose();
}
// Free Unmanaged memory.
Marshal.FreeHGlobal(nativeMemory);
}
}
Well, right now, you can't. . . This is a confirmed bug.
--
Jacob Grass
Microsoft .NET MVP
Check out http://windowsforms.net