473,473 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

terminate all threads in winform

Tom
hi friends

is there a way to terminate all threads in one go ?

Thanks
Tom
Nov 16 '05 #1
2 2545
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.

--
William Stacey, MVP

"Tom" <to********@optushome.com.au> wrote in message
news:41***********************@news.optusnet.com.a u...
hi friends

is there a way to terminate all threads in one go ?

Thanks
Tom


Nov 16 '05 #2
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

"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.

--
William Stacey, MVP

"Tom" <to********@optushome.com.au> wrote in message
news:41***********************@news.optusnet.com.a u...
hi friends

is there a way to terminate all threads in one go ?

Thanks
Tom

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Aaron | last post by:
Hello, I have an application that has several threads and non-blocking client sockets. When I try to terminate the program, although the application window disappear, but the program instance...
4
by: Dr. J | last post by:
How to terminate a blocked thread? In my form's "load" I launch a TCP listening thread that stays in an infinite loop waiting for incoming TCP packets. In this form's "closing" I try to...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
3
by: Kathy Burke | last post by:
Hi, I'm tired, so this question may be silly. I have a fairly long sub procedure. Based on one condition, I load another sub with the following: If Session("GRN") = "complete" Then txtScan.Text...
4
by: Jeremy Holt | last post by:
Hi, In a windows.forms application I would BeginInvoke a delegate on the UI thread to collect data from a database. When the call returns to the AsyncCallback, if the Control.InvokeRequired =...
9
by: Li Pang | last post by:
Hi I make an app which can run some sub processes through multiple threads. I'd like to know how to terminate all sub-threads when the main thread is closed thanks in advance
3
by: Me | last post by:
I am trying to figure out any issues with calling System.Reflection.MethodInfo.Invoke() when dealing with multiple threads. For instance.. Say I have a class that allows you to pass in a...
2
by: R. Nachtsturm | last post by:
Hi, i have the problem that when i create a low priority background thread, start it, and wait for it to finish that it does not seem to terminate even after it is finished.. if i use...
4
by: gsimmons | last post by:
I've been researching multi-threaded WinForms apps and thread synchronization stuff for a couple days since I'm working on refactoring a multi-threaded GUI app at work and want to be sure it's...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.