Solved

Closing a multithreaded application

Posted on 2006-11-09
4
359 Views
Last Modified: 2012-06-27
does any one know how i can close a multithreaded application ?

I cannot check for a boolean type, because each thread will stay waiting on the accepttcpclient() command of the socket object.

I have a list of thread that i started in my main program, can i destroy each thread in the destructor ?? and if yes, how ??
0
Comment
Question by:JoepKillaars
[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 Comments
 
LVL 1

Expert Comment

by:qing02051981
ID: 17912726
In C#

For example if you socket listening codes are like this

bool flag=true;

while(flag){
     //you listening codes here
}

You can close the socket so each thread does not stay at the socket.receivedata using socket.Close()

After that you can set the flag to false and kill the threads using abort

flag = false;
myThread.Abort();
0
 

Author Comment

by:JoepKillaars
ID: 17912739
I know that it can be done like that.

But in the thread there is waited for a connection by the socket.accepttcpclient() method, so i cannot create a while loop checking a boolean, I have to somehow force the accepttcpclient to stop listening and destroy the thread, without checking a boolean in a while loop.

Any one has suggestions ?
0
 
LVL 2

Expert Comment

by:basavaraj_kn
ID: 17912744
can you place your code here

Or simply place wait at the end of your programm so that your program waits till all thread finishes

Cheers..!
BAS
0
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 125 total points
ID: 17913610
You can set the IsBackground property (of the Thread object) to true before starting the thread, background threads dont prevent the application from closing and when the application is closed the CLR will stop any running background threads automatically:

http://msdn2.microsoft.com/en-gb/library/system.threading.thread.isbackground.aspx
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Loop 6 73
How to get time difference in minutes and seconds only between 2 dates 2 54
Do Wend Macro not working 22 56
"lblTime is not declared" 3 29
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

735 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