Dear Code Gurus,
I have an application that may create some scratch directories that should be deleted upone exiting. So, in my code for Form1 the following is done:
I also want to make sure that those directories are deleted if some exceptions are triggered in Form1 while running, so the following is done in Program.cs:Code:private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DeleteScratchDirectories(); }
The code seems to compile and run with no problems.Code:static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form1 FPtr = null; try { Application.Run(FPtr = new Form1()); } catch (Exception e10) { // Clean up the created mess before exiting if(FPtr!=null) FPtr.DeleteScratchDirectories(); MessageBox.Show( String.Format("Application is exiting with errors:\n{0}", e10.ToString()), "Exception Caught"); } }
Is this the correct way to handle situation like this? Are there any potential problems? Should anything be done in a different way?
Thank you for your help.




Reply With Quote