Re: AfxBeginThread on each user action X or re-use same thread (w



"William DePalo [MVP VC++]" wrote:
> "ultranet" <ultranet@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:4AE37BF6-F877-4B55-8DB1-385A2B73BCA1@xxxxxxxxxxxxxxxx
> >> > But most importantly, will an unexpected termination, such as due to an
> >> > uncaught exception, be handled this way as well?
> >>
> >> If you are waiting on a thread handle, and the thread terminates due to
> >> an
> >> uncaught exception, then your wait will end with the exception.
> > I suppose this can be handled with a catch(...)?
>
> Well, yes but this catch-all catch clause will only sometimes catch Win32
> structured exceptions (e.g. access violations) usually in debug but not
> release builds. It is generally considered a defect in the compiler that it
> does that and it should be fixed in VS2005. If you really want to catch SEs
> such as access viloations you should use _set_se_translator() to translate
> SEs to C++ typed exceptions.
Yes, so catch(...) will catch all C++ exceptions, but things like access
violations will still cause the process to crash, unless they are also
handled w/ a _se_translator_function, or terminate.

So far i haven't changed:
CWinThread* pThread =
AfxBeginThread(
MyFunction, this, THREAD_PRIORITY_NORMAL);
for every occurence of that action. And i have a question: does pThread need
to be deleted at the end of MyFunction?

But i'll probably change this to a single thread, w/ the following:
DWORD exitCode;
GetExitCodeThread(yourThread, &exitCode);
if (exitCode == STILL_ACTIVE)
{
// thread still alive
}
and start a new thread if not STILL_ACTIVE. I hope i'll get exitCode of 0 if
the handle is no longer valid, cause the thread has terminated. Since
MyFunction currently doesn't throw, it could only be dead w/ process still
running when _se_translator_function, or terminate is added.
So i could add the code above, and it should always be alive as long as the
process is alive. Then in the future i could add _se_translator_function, or
terminate.
.



Relevant Pages

  • Re: Terminating program in ProcessWndProcException
    ... NO program should terminate except by user directive. ... One of our best programmers spent six months removing all but one exit() ... A more serious question is where are these exceptions coming from? ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: Custom Service Terminates Unexpectedly
    ... The service is a .Net 2.0 service and handles all exceptions. ... Event log under Service Control Manager, ... terminate, it was right in the middle of an XSLT transform call. ... and run sc query against the service. ...
    (microsoft.public.windows.server.general)
  • Re: Custom Service Terminates Unexpectedly
    ... If the service can't handle any abnormal conditions (eg exceptions) then it may be impossible to know. ... Event log under Service Control Manager, ... It appears that some external event caused the service to terminate in this ... a utility that will log the sc query result to a log file if it happens again. ...
    (microsoft.public.windows.server.general)
  • Re: ApplicationException unhandled by user code
    ... any unhandled exceptions thrown by your application so that your ... program doesn't terminate or just so that you can handle the errors ... public void ApplicationThreadException(object sender, ... That should let you catch all your exceptions, and in .Net 1.1, it ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: AfxBeginThread on each user action X or re-use same thread (w
    ... > violations will still cause the process to crash, ... I believe that VS2005 has finally stopped comingling structured exceptions ... does pThread ... > GetExitCodeThread(yourThread, &exitCode); ...
    (microsoft.public.vc.language)