0

我有一个使用 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();
        }
    }
4

1 回答 1

0

任务调度程序意味着执行类似命令或控制台应用程序,无需 ui。

拆分出你打算在任务调度器下执行的代码,并将这些代码包装在 (dll) 下

然后您使用 ui 创建 2 个单独的项目:第一个是您现有的 winform,但您更改了代码以重用 dll。第二个项目是控制台应用程序,与winform类似的方法,重用dll逻辑。

现在将控制台应用程序用于任务调度程序。

于 2013-04-02T10:49:28.293 回答