Table of Contents

Class JobRunner

Namespace
VpnHood.Net.Toolkit.Jobs
Assembly
VpnHood.Net.Toolkit.dll

Provides a loop that checks its jobs at an interval and runs the ready ones, a few at a time.

public class JobRunner
Inheritance
JobRunner
Inherited Members

Remarks

It holds its jobs weakly: a job no one else references is dropped, and logged at Debug. Its loop runs for the process's life.

Constructors

JobRunner(TimeSpan)

Initializes a new instance of the JobRunner class and starts its loop.

public JobRunner(TimeSpan interval)

Parameters

interval TimeSpan

How often the runner checks its jobs.

Exceptions

ArgumentOutOfRangeException

The interval is not a timer's valid period.

Properties

FastInstance

Gets the shared runner that checks its jobs every 2 seconds.

public static JobRunner FastInstance { get; }

Property Value

JobRunner

Interval

Gets or sets how often the runner checks its jobs. A new interval restarts the countdown; the same one changes nothing.

public TimeSpan Interval { get; set; }

Property Value

TimeSpan

Exceptions

ArgumentOutOfRangeException

The interval is not a timer's valid period.

Logger

Gets or sets the logger of the jobs' failures, or null for none. The default is the process's VhLogger.Instance.

public ILogger? Logger { get; set; }

Property Value

ILogger

MaxDegreeOfParallelism

Gets or sets how many jobs run at once. The default is 2.

public int MaxDegreeOfParallelism { get; set; }

Property Value

int

Remarks

A new value counts for the jobs started after it; the ones running then finish beside them.

Exceptions

ArgumentOutOfRangeException

The value is less than 1.

SlowInstance

Gets the shared runner that checks its jobs every 10 seconds.

public static JobRunner SlowInstance { get; }

Property Value

JobRunner

Methods

Add(Job)

Adds a job, held weakly.

public void Add(Job job)

Parameters

job Job

The job.

Remove(Job)

Removes a job.

public void Remove(Job job)

Parameters

job Job

The job.