I am trying to catch the end of my form, so when the user exits, he saves "User exited" to a text file, this is my code:
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; } }
My problem is that I get this error:
"Make sure you don't have an infinite loop or infinite recursion"
Any ideas on how to fix this?
source share