Re: Thread Abort



The only way to abruptly terminate a thread is by calling Win32's API
TerminateThread(), BUT there is no valid reason to call it from managed code
and you should have very good reasons to do this from unmanaged code.
By doing this you simply corrupt your process, it might continue to work for
a small amount of time but sooner or later it will fail (crash or behave
unexpectedly). The same goes for Thread.Abort on another thread than the
calling thread, but here at least you have a chance to unload the
Application domain (if this runs in a non default AppDomain).

Willy.


"[Yosi]" <Yosi@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CA7CCE1A-BA26-425D-B9A0-6C40D2A5D78B@xxxxxxxxxxxxxxxx
>H Marki,
> You are right about such a Boolean inside the thread this what I done.
> But , in some cases this not good enough, one of the scenarios is as
> following :
>
> I create a thread , the thread call DLL function , this function write to
> an
> IO address or write buffer to external device using LPC/USB (takes 2
> minutes)
> , while this function write to IO, another thread which call DLL function
> that polling (read) GPIO (General Port IO) , read in loop until this GPIO
> become zero this happen for example when power failed occur, in this case
> I
> want to abort the write thread immediately and not to wait until it is
> finish
> . how can I do that ? the Boolean solution is not good enough . I want
> function like process.Kill immediately . There are a lot of reason in our
> industry that need such terminator function
>
> "Mark R. Dawson" wrote:
>
>> Hi Yosi,
>> there should be no reason why you cannot abort a suspended thread, what
>> behaviour are you seeing that makes you think the thread is not being
>> aborted?
>>
>> Even calling Abort on a thread does not guarantee that the thread will
>> stop immediately. Aborting a thread throws a ThreadAbortException which
>> will
>> cause catch and finally statements to be entered, plus the
>> ThreadAbortException is rethrown at the end of each catch automatically
>> so
>> you may go into many regions of code befoer the thread is officially
>> aborted.
>>
>> You should really try to find some graceful way of stopping your thread,
>> such as setting a boolean inside the thread method to indicate it should
>> stop, trying to stop the thread at arbitary locations in your code may
>> cause
>> unforseen errors.
>>
>> Mark
>>
>> "[Yosi]" wrote:
>>
>> > Why I can't abot a susspended thread.
>> > Who can terminat a thread imediatly without consider to its stat or
>> > execution?


.



Relevant Pages

  • Re: Kooks, Trolls and Witches: An Appeal To Reason
    ... >> to justifying name calling as reasonable within this ... Reason can solve anything. ... > of the insult is another matter. ...
    (sci.bio.evolution)
  • Re: Learning to use decorators with classes
    ... and it's a FAQ FWIW - but since there's no ... The reason we have to explicitly mention it as first ... this method object, it inserts the instance as first ... IOW, and to make a long story short, calling ...
    (comp.lang.python)
  • Re: Opening
    ... lying when I say I'm not making a moral judgement. ... whereas not remembering names is friendlier. ... see no reason to get all defensive about it either. ... You're calling complete strangers ...
    (rec.arts.sf.composition)
  • Re: Pocket PC flicker
    ... Michael, this is the whole reason they don't want you calling ... > ControlBox ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Kennedy Passes -- Let the Ghouls Rejoice
    ... Jerry has given the reason this happened and the reason he got away ... who disagreed with him, such as myself, should admire. ... name calling is all Jim ever has. ...
    (rec.gambling.poker)

Quantcast