我正在尝试关闭我的表单,以便当用户退出时,它将“用户已退出”保存到文本文件中,这是我的代码:
private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (String.IsNullOrEmpty(directory))
{
Close();
e.Cancel = false;
}
else
{
string time = DateTime.Now.ToString("hh:mm");
TextWriter msg = new StreamWriter(directory, true);
msg.WriteLine(" (" + time + ") == " + uName + " Has Left The Chat == ");
msg.Close();
Close();
e.Cancel = false;
}
}
我的问题是,我收到此错误:
“确保您没有无限循环或无限递归”
有想法该怎么解决这个吗?