Solved

terminate all child threads

Posted on 2003-10-28
6
188 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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

Technology Partners: 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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

624 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