Solved

terminate all child threads

Posted on 2003-10-28
6
175 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

863 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

18 Experts available now in Live!

Get 1:1 Help Now