Solved

Closing a multithreaded application

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

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 article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Progress

617 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