我试图让(我的测试版)应用程序尽可能多地运行,所以我在try-catch
里面放了另一个Program.cs
,以防发生一些严重错误并意外关闭应用程序。并且catch
我重写了Application.Run()
方法,以便应用程序可以在因任何原因终止后自行恢复。
针对这种特定情况制定这样的计划是否正确?
如果不正确,那么为了保持程序运行,还有什么建议?
这是演示我的意思的示例代码:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Hossein;
using Pishro.Classes;
namespace Pishro
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMain());
}
catch(Exception exc)
{
API.SaveAndShowLog(exc);
Application.Run(new frmMain());
}
}
}
}