0

I have a windows application in Dot-net which consists of various Analytics tests. When user select a particular test(Checkbox) and submit it (clicking the button) then at the back-end SQL query gets executed and user gets a result-set of that particular test.

Now a requirement is, user will select a particular test and will give a time-stamp (time at which test will run) to get the output at his email ID using auto scheduler (without any user intervention with application). Auto scheduler will get triggered at specified time and will run the specific selected tests.

How to implement Auto scheduler with Windows application? I am trying to create Windows service in Dot-net but issue is how this service get the instance of Windows application and how it will run the selected tests using scheduler approach?

As per my understanding, I can run only script file using scheduler hence how to achieve this auto-scheduling of these tests of Windows application in Dot-net.

rahul16590
  • 391
  • 1
  • 8
  • 19
  • usually you would implement the windows built in task scheduler, it would then fire your app with the user determind options -so your app needs to take parameters of a file with the options, and then you can use your app to add a scheduled task to the task scheduler to run as that user, those settings. – BugFinder Feb 20 '17 at 10:57

1 Answers1

0

You can use the Task Scheduler Managed Wrapper. Download it manually and reference from your project or install using nuget packages. The example source code and more information are to be found here: 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");
      }
   }
}

Cheers,

Community
  • 1
  • 1
Dawid Dworak
  • 310
  • 2
  • 12