Problem with Thread.Abort()

  • Thread starter Thread starter Ennixo
  • Start date Start date
E

Ennixo

hi,

i coded an application in which i can move a slider to define a radius
and it computes a gaussian blur in a thread.

because the Scroll event of the slider is often raised, i use one thread
(declared in the form's class) that i abort when it is already existing
and running.

this works well but sometimes i've got this error (translated from
french) : The thread is suspended ; trying to abort.

it comes at the next line of myThread.Abort() and if i put it in a
try/catch it freezes instead of showing this error.

what's the problem ?
 
Ennixo said:
i coded an application in which i can move a slider to define a radius
and it computes a gaussian blur in a thread.

because the Scroll event of the slider is often raised, i use one thread
(declared in the form's class) that i abort when it is already existing
and running.

Ouch, not a nice idea. Thread.Abort is not a good idea, IMO. You should
tell your thread to stop running in a more controlled manner.

See
http://www.pobox.com/~skeet/csharp/threads/abort.shtml
this works well but sometimes i've got this error (translated from
french) : The thread is suspended ; trying to abort.

it comes at the next line of myThread.Abort() and if i put it in a
try/catch it freezes instead of showing this error.

what's the problem ?

Are you doing any UI work in the worker thread? If so, that's a bad
idea too:
http://www.pobox.com/~skeet/csharp/threads/winforms.shtml
 
Back
Top