Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.
/ WinTask Public archive

A really simple wrapper for the TaskScheduler library, for better code readability.

Notifications You must be signed in to change notification settings

sos-dll/WinTask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

WinTask

A really simple Task wrapper for the TaskScheduler library, made for better code readability.

Examples

Create a daily task, testing for equality, and removing a task

const string TaskName = "MyDailyTask"; // Task name (keep it unique).
string exePath = new FileInfo(Assembly.GetExecutingAssembly().Location).FullName; // A full path of this program, which will be executed on daily basis.
using (var task = WinTask.With(TaskName)                 // Get existing -or- create a new task.
                         .Description("The daily task")  // Set a new description for this task.
                         .RemoveTriggers()               // Removes all triggers (on existing task).
                         .DailyTrigger()                 // Add a new daily trigger.
                         .RemoveActions()                // Removes all actions (on existing task).
                         .ExecAction(exePath)            // Add an action.
                         .Update())                      // All ready, update the task definition.
{ /* do something more with the task in here, if needed */
    Task t = task;            // Implicit cast from WinTask to Task.
    var winTask = (WinTask)t; // Explicit cast from Task to WinTask.
    bool areEqual = winTask == task; // Implemented equality test, yay.
    if (areEqual) {
        Console.WriteLine("These two are the same task.");
    } else {
        Console.Error.WriteLine("Something has gone wrong with equality test! Please report a bug.");
    }
    task.Delete(); // Delete the task.
}

Create a (special) monthly task

For example, if you wanted to create a task which is run on 26th February, and on 30th for every other month:

const string TaskName = "MyMonthlyTask";
string exePath = new FileInfo(Assembly.GetExecutingAssembly().Location).FullName; // A full path of this program, which will be executed on monthly basis.
using (var task = WinTask.With(TaskName)
                         .Description("The monthly task")
                         .RemoveTriggers()
                         .MonthlyTrigger(26, MonthsOfTheYear.February)
                         .MonthlyTrigger(30, MonthsOfTheYear.AllMonths & ~MonthsOfTheYear.February)
                         .RemoveActions()
                         .ExecAction(exePath)
                         .Update())
{ /* do something more with the task in here, if needed */
}

Omitted-using syntax:

You can also work with WinTask without using-statement:

WinTask.With("YourTaskName")
       /* stuff */
       .Update()
       .Dispose(); // Make sure you do call Dispose at the end!

Test if there is a task with the given name

bool taskExists = WinTask.Get("YourTaskName"); // Implicit bool operator for WinTask allows you to do this :)

Quickly remove a task by name

WinTask.Get("YourTaskName")?.Delete(true);

Downloads

You can download the latest build from the releases page.

License

WinTask uses the same license as its core library, see TaskScheduler. As of this post date (7th August 2019), it is licensed under MIT.

About

A really simple wrapper for the TaskScheduler library, for better code readability.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages