我有一个使用 Windows 窗体的 C# 应用程序。我的应用程序工作正常,但是当我想通过操作系统(Windows 7)使用计划任务启动它时,它不会加载 Form1_load 方法。我该如何解决这个问题?
这是 Form1_load 方法的主体:
private void Form1_Load(object sender, EventArgs e)
{
try
{
bool fResult = false;
fResult = registerDeviceNotification();
g_oGeneratorManager = new CGeneratorManager();
if (true != fResult)
{
Debug.WriteLine("Register device notification failed");
MessageBox.Show("Register device notification failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
lblStatus.Text = "Running";
}
catch (Exception ex)
{
this.Visible = false;
CLog.Err(ex.Message);
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}