예제 #1
0
        static void Main()
        {
            string errorPath = @"ErrorLog.txt";

            if (File.Exists(errorPath))
            {
                File.Delete(errorPath);
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            AppDomain.CurrentDomain.UnhandledException +=
                (sender, args) => HandleUnhandledException(args.ExceptionObject as Exception);
            Application.ThreadException +=
                (sender, args) => HandleUnhandledException(args.Exception);
            AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) =>
            {
                string log = (DateTime.Now + " - " +
                              eventArgs.Exception.Message);
                using (System.IO.StreamWriter file =
                           new System.IO.StreamWriter(errorPath, true))
                {
                    file.WriteLine(log);
                }
            };
            F000_Login login = new F000_Login();

            login.Show();
            Application.Run();
        }
        // Close all currently opened forms when this form is closed, then re-open Login.
        private void FrmData_FormClosed(object sender, FormClosedEventArgs e)
        {
            List <Form> openForms = new List <Form>();

            foreach (Form f in Application.OpenForms)
            {
                openForms.Add(f);
            }
            foreach (Form f in openForms)
            {
                f.Close();
            }
            F000_Login login = new F000_Login();

            login.Show();
            login.Focus();
        }