R
Ryan Seghers
I've got a program that has no user interface (like a service but not
actually a Windows Service yet) in which I'd like to handle
OutOfMemoryExceptions. I'd at least like to log the failure before exiting,
if possible. I understand that it probably takes some memory to continue
operating, even just to write a message to an open file, but if the
allocation that triggered the OutOfMemoryException was large then there
probably really is a little memory left. I am causing/throwing the
OutOfMemoryException from a Thread other than the main one, so this is a
case where UnhandledExceptionEventHandler works for other types of
exceptions.
Unfortunately, unless I'm missing something it looks like my
UnhandledExceptionEventHandler doesn't get called for OutOfMemoryExceptions,
even if there is plenty of memory and I just threw the OutOfMemoryException
explicitly myself.
Doing a try/catch at the top of every thread (there are many) is
undesirable, plus any particular worker thread doesn't have any idea what
should be done for the whole service when this happens - so I'd have to
convert to my own ApplicationException subclass and recognize that in the
UnhandledExceptionEventHandler. I'd prefer to handle it in one place for
the entire service AppDomain.
Any ideas on good ways to handle this?
Ryan Seghers
actually a Windows Service yet) in which I'd like to handle
OutOfMemoryExceptions. I'd at least like to log the failure before exiting,
if possible. I understand that it probably takes some memory to continue
operating, even just to write a message to an open file, but if the
allocation that triggered the OutOfMemoryException was large then there
probably really is a little memory left. I am causing/throwing the
OutOfMemoryException from a Thread other than the main one, so this is a
case where UnhandledExceptionEventHandler works for other types of
exceptions.
Unfortunately, unless I'm missing something it looks like my
UnhandledExceptionEventHandler doesn't get called for OutOfMemoryExceptions,
even if there is plenty of memory and I just threw the OutOfMemoryException
explicitly myself.
Doing a try/catch at the top of every thread (there are many) is
undesirable, plus any particular worker thread doesn't have any idea what
should be done for the whole service when this happens - so I'd have to
convert to my own ApplicationException subclass and recognize that in the
UnhandledExceptionEventHandler. I'd prefer to handle it in one place for
the entire service AppDomain.
Any ideas on good ways to handle this?
Ryan Seghers