【问题标题】:Schedule a c# program in windows task scheduler在windows任务调度器中调度一个c#程序
【发布时间】:2012-04-26 14:28:45
【问题描述】:

我有一些代码希望每 30 分钟运行一次。在 windows 任务计划程序 -> 创建任务 -> 操作 -> 新建 - 有一个地方可以插入脚本/程序。 我的问题是我需要创建什么样的项目来添加我的程序,以及我需要添加什么样的文件 - dll?

我希望每 30 分钟运行一次 30~ 行代码,从网络中获取一些东西,处理它并将其插入到数据库中。

谢谢。

【问题讨论】:

  • 我真的不在乎它是什么,我猜它可能是一个 exe..

标签: c#-4.0 scheduled-tasks


【解决方案1】:

任务计划程序运行普通的 EXE。

你不需要做任何特别的事情。

【讨论】:

  • 但请记住,EXE 将运行但不可见,因此如果您触发 winform 应用程序,例如您将看不到表单。
  • @Dan:这取决于您将任务设置为哪个用户。
【解决方案2】:
    using System;
    using Microsoft.Win32.TaskScheduler;

    class Program
    {
     static void Main(string[] args)
    {
    // Get the service on the local machine

    using (TaskService ts = new TaskService())
    {

     // Create a new task definition and assign properties
      TaskDefinition td = ts.NewTask();
      td.RegistrationInfo.Description = "Does something";

         // Create a trigger that will fire the task at this time every other day
         td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });

         // Create an action that will launch Notepad whenever the trigger fires
         td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));

         // Register the task in the root folder
         ts.RootFolder.RegisterTaskDefinition(@"Test", td);

         // Remove the task we just created
         ts.RootFolder.DeleteTask("Test");
        }
     }
   }

【讨论】:

    猜你喜欢
    • 2012-04-21
    • 1970-01-01
    • 2013-02-18
    • 1970-01-01
    • 2021-07-20
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多