Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

System.Environment.HasShutdownStarted

49 views
Skip to first unread message

Andrei Ignat

unread,
Jun 13, 2002, 2:39:41 AM6/13/02
to
I found an old example using System.Environment.HasShutdownStarted in the
Finalizer like this:

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);
}
}


Jacob Grass (MVP)

unread,
Jun 17, 2002, 5:28:07 PM6/17/02
to
Andrei Ignat wrote:
>
> 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???
>

Well, right now, you can't. . . This is a confirmed bug.


--
Jacob Grass
Microsoft .NET MVP
Check out http://windowsforms.net


0 new messages