Solved

terminate all child threads

Posted on 2003-10-28
6
174 Views
Last Modified: 2013-11-20
I have this program that creates many threads that updates a screen with data .When i stop the program to clear the screen it crashes.So can anyone tell me how to stop all other threads without closing the main window(gui).I want to close all threads and leave the screen as it is,

Thanks.
0
Comment
Question by:rc3000
  • 4
6 Comments
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9636256
I can't understand what you mean.
But you can "close thread" by calling TerminateThread.
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9636277
But keep in mind that:

TerminateThread is used to cause a thread to exit. When this occurs, the target thread has no chance to execute any user-mode code and its initial stack is not deallocated. DLLs attached to the thread are not notified that the thread is terminating.

TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:

If the target thread owns a critical section, the critical section will not be released.
If the target thread is allocating memory from the heap, the heap lock will not be released.
If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9636302
So the proper way is to "say" the thread, that it must stop by setting a variable or an event.
The thread have to check the variable or event in it's execution loop.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:rc3000
ID: 9636365
hi gloomy ,
   your answer is also gloomy for me.Because if i use terminatethread then the window closes and some other threads continue to run.If i use Exitprocess(0) then it exits gracefully but the window closes .I want the window the main window to remain open while all  the background processing comes to a stop.I hope this clarifies things.I am increasing the number of points by 100.
0
 
LVL 13

Accepted Solution

by:
SteH earned 135 total points
ID: 9640280
The example on
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/html/_sample_mfc_MTGDI.asp
should be very helpful for your purpose. There several (hundred) threads can be started and stopped without affecting the main program.
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9640401
I still don't understand what all this about.
Let's go step-by-step.
How do you create the threads and what the thread have to do?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now