Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to stop specific thread in multithreads and to destroy all variables and objects created in specific thread
    primarykey
    data
    text
    <p>I'm developing a client-server program. I use C# programming language and .net framework 4. At there, whenever new client is connected to the server, the server will create new thread to process each client. If one of the client is disconnected, the thread which controls this disconnected client will also be stopped (killed). I don't know how to stop this specific thread among multiple threads. The pseudo-code of my program will be like that:</p> <p><strong>Server Side Program:</strong></p> <pre><code>Thread t; private void form1_load(object sender, EventArgs e) { startserver(); } void startserver() { t = new Thread(waitclientconnection); t.start(); } void waitclientconnection() { //namedpipeserverconnection code //waitforclientconnection if (clientOne is connected) { startserver(); //create new thread to wait connection for next client } //object and variable that created within the thread Clientprofile cp = new Clientprofile(); String clientstate = "...."; if (clientOne sends "close" message) { //the thread that controls ClientOne will be killed &lt;-- This is the point that I would like to solve } } </code></pre> <p>I confessed that the program is a little complex but currently I have only this way to implement my program. I found some solutions that suggested to declare Boolean variable to control the thread stop or running using while looping. But in my program, this way can stop the whole thread and cannot able to create new threads for new connected clients. Moreover, I also want to know whether the variables and objects created in each specific thread can also be destroy from the memory when this thread is stopped. Imagine that if hundred clients were connected within one hour and currently only 10 clients are in connection. I only want to keep only objects and variables in memory for only these 10 clients. The question is complex but I'm sure all of you can able to solve and give any suggestions. Really hope for your suggestions... </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload