terminate all threads in winform

  • Thread starter Thread starter Tom
  • Start date Start date
That is a loaded question. What threads, where? You should design your
threads to always check some sync'd flag (i.e. closed, stopped, etc) and
they will shut down when hit. If thread is blocking then it depends what
they are blocking on and interrupt that (say socket, monitor, etc.) and
catch/handle exception as needed. There is no simple answer to this as it
takes careful attention to get it right for your situation. Yeh you can
abort() them all and burn your app down to the ground, but obviously not a
good way to go.
 
Hi,

On this subject, given (say) the following situation, what's a good way of
stopping the thread ASAP (if abort() is not well regarded)? :

- A main UI thread that can spawn preview windows
- Each preview window has a thread it uses to calculate stuff to display
in itself. These operations can be lengthy and not easily split down to
(say) less than a second of time
- The preview worker threads don't contain any resources that require
explicit destruction (they contain only value types, for example)

If you want to close a preview window, you don't want to wait for a second
for the worker thread to finish. One solution is to do something to the
worker that means that when it finishes, it just drops its calculation, but
that doesn't seem good to me.

So given that, is there an acceptable way of killing the thread off (for
example refactoring the worker thread so it is more granular)? We're sort of
in this situation (except our threads are executing some unmanaged C++ code
that's extremely processor intensive and not easily interrupted nicely),
andso far I've not come up with a nice solution.

Cheers,

Steve
 
Back
Top