在 C# 中为项目使用表单时,我有我的主表单 (mainForm)。这个表单,当点击button1时,它会为第二个表单(actionForm)创建一个新线程。这一个,和主要的一样,当我点击button1时,它为thid Form(registerForm)创建一个新线程。这第三个表单,当我关闭它时,它必须重新创建第二个表单。
问题是,线程继续运行。表格,已关闭。但是当我点击第三种形式的“X”时,它会循环,创建新的actionForms。
创建新线程时如何停止线程?有没有更好的方法来使用表格?
代码:
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)
{
}
}
}