【问题标题】:How to run Windows application using Auto Schedular如何使用自动调度程序运行 Windows 应用程序
【发布时间】:2017-02-20 10:53:44
【问题描述】:

我在 Dot-net 中有一个 Windows 应用程序,其中包含各种分析测试。当用户选择一个特定的测试(复选框)并提交它(单击按钮)然后在后端 SQL 查询被执行并且用户获得该特定测试的结果集。

现在的要求是,用户将选择一个特定的测试,并给出一个时间戳(测试将运行的时间),以便使用自动调度程序(无需用户干预应用程序)在他的电子邮件 ID 处获取输出。自动调度程序将在指定时间触发并运行特定选定的测试。

如何使用 Windows 应用程序实现自动调度程序?我正在尝试在 Dot-net 中创建 Windows 服务,但问题是该服务如何获取 Windows 应用程序的实例以及它将如何使用调度程序方法运行选定的测试?

据我了解,我只能使用调度程序运行脚本文件,因此如何在 Dot-net 中实现这些 Windows 应用程序测试的自动调度。

【问题讨论】:

  • 通常你会实现windows内置的任务调度程序,然后它会使用用户确定选项来触发你的应用程序 - 所以你的应用程序需要使用选项获取文件的参数,然后你可以使用您的应用程序将计划任务添加到任务计划程序以作为该用户运行,这些设置。

标签: c# .net vb.net


【解决方案1】:

您可以使用Task Scheduler Managed Wrapper。手动下载它并从您的项目中引用或使用 nuget 包安装。示例源代码和更多信息可以在这里找到:Creating Scheduled Tasks

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-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-20
    • 2018-03-22
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    相关资源
    最近更新 更多