Hi my window form application have a dependency to file where it check the content and if the content is 0 then app should run otherwise it should message that instance is running fine. This is working fine when I am closing the app either by cross button form the form or form closed by its own (Environment.Exit(0);
) but when I am closing the Window form application either by task manager or from the stop button of Visual studio ...the content of file is not changing to 0 . I have added the following code at:
private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
{
File.WriteAllText(filename2, "0");
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
File.WriteAllText(filename2, "0");
}
And also before Environment.Exit(0);
:
if (Status.Equals("Data Got Loaded"))
{
File.WriteAllText(filename2, "0");
aTimer.Stop();
Environment.Exit(0);
}
Do I need to somewhere else so that application should write to the file before getting closed.