While using forms in C# for a project, i have my main Form (mainForm). This form, when clicking the button1, it creates a new thread for the second Form (actionForm). This one, does the same as the main, when i click button1, it creates a new thread for the thid Form (registerForm). This third Form, when i close it, it must recreate the second form.
The problem is that, the threads keep running. The forms, were closed. But when i click the "X" in the third form, it loops, creating new actionsForms.
How can i stop the threads when creating new ones? Is there a better way to use the Forms?
Code:
namespace Lector
{
public partial class register : Form
{
public register()
{
InitializeComponent();
}
//New thread for Form2
public static void ThreadProc()
{
//New Form
Application.Run(new Form2());
}
//Close Form
private void Registro_FormClosing(Object sender, FormClosingEventArgs e)
{
regresoForma();
}
private void regresoForma()
{
//New thread
System.Threading.Thread nuevoRegistro2 = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
//Start thread
nuevoRegistro2.Start();
//Close this form
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}