Link to home
Start Free TrialLog in
Avatar of addicktz
addicktz

asked on

On Crash, Restart Application

I have a crawler I wrote that randomly crashes (crash comes from a window dll). When the program crashes, a window pops up saying "debug, send error report, etc..". I want to prevent that window from opening and restart the application, I am including the code I am currently attempting to use, but I have had zero luck, any ideas on how I can accomplish this?
public static Form1 form1;
        public static System.Threading.Timer tmr;
        public static System.Threading.Timer tmr2;
 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            bool b = true;
 
            while (b == true)
            {
                try
                {
                    tmr = new System.Threading.Timer(new System.Threading.TimerCallback(onTimeout), null, 5000, 5000);
                    form1 = new Form1();
                    Application.Run(form1);
                }
                catch (Exception ex)
                {
 
                }
 
                System.Threading.Thread.Sleep(30000);
            }
        }
 
        
        public static void onTimeout(object obj)
        {
            tmr2 = new System.Threading.Timer(new System.Threading.TimerCallback(onTimeoutTimeout), null, 1000, System.Threading.Timeout.Infinite);
            bool a = form1.IsAlive();
            if (a == true)
            {
                tmr2.Dispose();
            }
        }
 
        public static void onTimeoutTimeout(object obj)
        {            
            form1.Dispose();
        }

Open in new window

SOLUTION
Avatar of Gautham Janardhan
Gautham Janardhan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial