我遇到了一个奇怪的错误。我调用了Application.Restart();
假设它将重新启动程序一次的方法。但是,当我调用它时,它重新启动并启动程序不是一次而是两次,在窗口上产生了两个表单。为什么会这样?请帮忙!
这是我的代码:
Main.cs
private void Login_Load(object sender, EventArgs e)
{
// DO some checkings here to see if setting is needed
if (SettingIsNeeded)
{
SettingsForm Settings = new SettingsForm();
Settings.Show();
}
}
SettingsForm.cs
private void button1_Click(object sender, EventArgs e)
{
if (Settings.Default.COM != comboBox1.Text || Settings.Default.Gate_IP != textBox1.Text || Settings.Default.Server_Address != textBox2.Text) //Check if change has been made
{
Settings.Default.COM = comboBox1.Text;
Settings.Default.Gate_IP = textBox1.Text;
Settings.Default.Server_Address = textBox2.Text;
Settings.Default.Save();
settingschanged = true;
this.Close();
}
settingschanged = false;
this.Close();
}
private void COM_Settings_FormClosing(object sender, FormClosingEventArgs e)
{
if (settingschanged)
{
Application.Restart(); //This is where only the method will be called for restart.
}
}