Re: Possible huge clue into unmanged/managed problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Willy Denoyette [MVP] (willy.denoyette_at_pandora.be)
Date: 02/01/05


Date: Tue, 1 Feb 2005 21:18:52 +0100

If you happen to abort a thread asynchronously, that means an exception can
bet thrown at any moment during program execution, you possibly have
corrupted the application state.
Consider following thread procedure

void SomeProc()
{
    lock(myLock)
    {
    }
}
, when the exception is thrown during the execution of the finalize clause
(compiler generated from lock()), chances are that the lock is not released.
If it happens that you are executing unmanaged code during Abort, chances
are that locks held by your unmanaged code will not being released, buffers
not freed, semaphores not cleared etc.
If it happens during managed execution of global state initialization
(static's), you'll end with incorrectly initialized global state.

So, I think it's clear there is no other option then to exit the process or
throw away the application domain.

Not sure what you mean with:
terminate the last thread in an application shouldn't the process be
> terminated automatically by the system?
>
calling Thread.Abort on your current thread, is a synchronous Abort
(synchronous exception), and yes if it happens on the last managed thread in
the application, the CLR will shutdown the process.

Willy.

"cody" <deutronium@gmx.de> wrote in message
news:%23skSu%23ICFHA.268@TK2MSFTNGP10.phx.gbl...
> What do you mean with "terminate the process"? Why should I have to
> terminate the whole application if I only want to terminate one thread?
> And if a terminate the last thread in an application shouldn't the process
> be terminated automatically by the system?
>
> "Willy Denoyette [MVP]" <willy.denoyette@pandora.be> schrieb im
> Newsbeitrag news:OO1bdOHCFHA.4004@tk2msftngp13.phx.gbl...
>>
>>
>> "cody" <deutronium@gmx.de> wrote in message
>> news:u089dKGCFHA.3092@TK2MSFTNGP10.phx.gbl...
>>> You simply have to call return from the thread method to terminate a
>>> thread
>>> the clean way.
>>>
>>
>> And what if the thread is blocked or is in an infinite loop?
>> There is nothing wrong with Thread.Abort as long as you call it
>> synchronously. When called asynchronously you have to terminate the
>> process when done or unload the application domain if not running in the
>> primary domain.
>>
>> Willy.
>>
>
>



Relevant Pages

  • Re: Possible huge clue into unmanged/managed problem
    ... If you happen to abort a thread asynchronously, that means an exception can ... when the exception is thrown during the execution of the finalize clause ... > terminate the whole application if I only want to terminate one thread? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Threadabortexception
    ... But u say exception is rethrown from the point of abortion to start ... > The abort causes an exception to be raised, and even if a catch block handle ... Aborting a thread injects an abort exception into the target ... > execution paths, such as finally blocks and static constructors, that you ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Threadabortexception
    ... But u say exception is rethrown from the point of abortion to start ... > The abort causes an exception to be raised, and even if a catch block handle ... Aborting a thread injects an abort exception into the target ... > execution paths, such as finally blocks and static constructors, that you ...
    (microsoft.public.dotnet.general)
  • Re: Try Finally...
    ... >The program will terminate in the finally block ... execution goes to ... the application's default exception handler, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Stopping a program
    ... > I'd like to stop a program (i.e. terminate its execution) without ... > raising an exception if some condition is met, ...
    (comp.lang.python)