I tried to make a new thread using the winform application. Here is my sample code.
public static bool stop = false;
private Thread mythread(){
Thread t = new Thread(delegate() {
while(!stop){
// Something I want to process
}
});
return t;
}
private Button1_click(object sender, EventArgs e){
stop = true; // I know it doesn't work
this.Dispose();
this.Close();
}
public Main(){
InitializeComponent();
Thread thread = mythread();
thread.Start();
}
When the button1 is clicked, new thread and winform should be terminated, but new thread is still working. Is there any way to terminate the new thread?
ps: I tried to change my code reffering to the MSDN site example but it only made it more complicated.