C# Class Examples.PeriodicTaskFactory

Factory class to create a periodic Task to simulate a System.Threading.Timer using Tasks.
Afficher le fichier Open project: pushtechnology/diffusion-examples Class Usage Examples

Méthodes publiques

Méthode Description
Start ( System.Action action, int intervalInMilliseconds = Timeout.Infinite, int delayInMilliseconds, int duration = Timeout.Infinite, int maxIterations = -1, bool synchronous = false, CancellationToken cancelToken = newCancellationToken(), TaskCreationOptions periodicTaskCreationOptions = TaskCreationOptions.None ) : Task

Starts the periodic task.

Exceptions that occur in the action need to be handled in the action itself. These exceptions will not be bubbled up to the periodic task.

Private Methods

Méthode Description
CheckIfCancelled ( CancellationToken cancellationToken ) : void

Checks if cancelled.

MainPeriodicTaskAction ( int intervalInMilliseconds, int delayInMilliseconds, int duration, int maxIterations, CancellationToken cancelToken, Stopwatch stopWatch, bool synchronous, System.Action wrapperAction, TaskCreationOptions periodicTaskCreationOptions ) : void

Mains the periodic task action.

Method Details

Start() public static méthode

Starts the periodic task.
Exceptions that occur in the action need to be handled in the action itself. These exceptions will not be bubbled up to the periodic task.
public static Start ( System.Action action, int intervalInMilliseconds = Timeout.Infinite, int delayInMilliseconds, int duration = Timeout.Infinite, int maxIterations = -1, bool synchronous = false, CancellationToken cancelToken = newCancellationToken(), TaskCreationOptions periodicTaskCreationOptions = TaskCreationOptions.None ) : Task
action System.Action The action.
intervalInMilliseconds int The interval in milliseconds.
delayInMilliseconds int The delay in milliseconds, i.e. how long it waits to kick off the timer.
duration int /// The duration. /// If the duration is set to 10 seconds, the maximum time this task is allowed to run is 10 seconds. ///
maxIterations int The max iterations.
synchronous bool /// if set to true executes each period in a blocking fashion and each periodic execution of the task /// is included in the total duration of the Task. ///
cancelToken System.Threading.CancellationToken The cancel token.
periodicTaskCreationOptions TaskCreationOptions /// used to create the task for executing the /// . ///
Résultat Task