Solved

terminate all child threads

Posted on 2003-10-28
6
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sumDigits challenge 9 178
VBA "SendKeys" Syntax for Multiple Keystrokes 7 133
Sed question 2 139
Bartender label printing - switch on and off graphics 3 91
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.

733 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