Dave, thanks for your response.
Bellow is sample code. If you pass any argument on comman line, it works ok.
If you run it with no arg, IndexOutOfRangeEception is thrown, and, on my
machine (.NET 1.1), I cannot see that ~ReleaseMe finalizer and
CurrentDomain_ProcessExit handler were invoked.
(Also, if I do not setup console event handler, CTRL-C also kills the app
without finalizer and handler get called.)
What am I doing wrong? Now, in order to make my app working somehow, I have
console event, process exit event and unhandled exception event handlers to
clean those sensitive native resources on vm exit...
Thanks,
Ales
---------------------------
namespace CleaningUp
{
class ReleaseMe
{
~ReleaseMe()
{
Console.WriteLine("~ReleaseMe");
}
}
class Class1
{
static void CurrentDomain_ProcessExit(object sender, EventArgs args)
{
Console.WriteLine("CurrentDomain_ProcessExit");
}
[STAThread]
static void Main(string[] args)
{
ReleaseMe rm = new ReleaseMe();
AppDomain.CurrentDomain.ProcessExit += new
EventHandler(CurrentDomain_ProcessExit);
args[0] += "throw exception, now!";
Console.WriteLine("press any key to exit");
Console.Read();
}
}
}
[quoted text, click to view] "Dave" <noSpamdlevineNNTP2@wi.rr.com> wrote in message
news:O8F%23V47wDHA.1704@TK2MSFTNGP10.phx.gbl...
> The best way to ensure that native resources get cleaned up is to wrap
each
> native resource in a managed class, provide a Finalizer method for each
one,
> and release the resource in that method (use fields to indicate the
> acquired/release status so you don't try to release it twice). The
Finalizer
> will always get called when the system is shutting down.
>
> In C# the Finalizer syntax is ~SomeClass(){}
>
> I'm not sure why you are not seeing the Process.Exit event. You should see
> that before the finalizers are called. Perhaps if you posted some code we
> could look at it. Is this a console app?
>
> "Ales Pour" <ales.pour@systinet.com> wrote in message
> news:exmROT7wDHA.1680@TK2MSFTNGP12.phx.gbl...
> > Hello,
> >
> > in my app, I need to cleanup some native resources whenever the app
exits,
> > either gracefully or not.
> >
> > So I wrote ProcessExit event handler, console event handler to catch
> CTRL-C
> > (why the ProcessExit is not called when user breaks running app woth
> > CTRL-C?). Now, when an unhandled exception is thrown, ProcessExit
handler
> > does not get called; why? How can I make sure to be notified when
virtual
> > machine is shutting down?
> >
> > Many thanks,
> > Ales Pour
> >
> >
>
>