Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Closing a multithreaded application

Posted on 2006-11-09
4
Medium Priority
?
375 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Six Sigma Control Plans

719 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