Solved

Closing a multithreaded application

Posted on 2006-11-09
4
325 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
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 …
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…

744 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

10 Experts available now in Live!

Get 1:1 Help Now