Table of Contents

TimerFactory Class

Definition

Namespace
Cuemon.Threading
Assemblies
Cuemon.Core.dll
Source
src/Cuemon.Core/Threading/TimerFactory.cs

Provides access to factory methods for creating and configuring Timer instances.

public static class TimerFactory
Inheritance
TimerFactory

Examples

The following example creates a non-capturing timer that fires every two seconds after an initial one-second delay. The callback prints "Timer ticked" each time it executes; the timer is disposed after five seconds.

// Program.cs
using System;
using System.Threading;
using Cuemon.Threading;

using var timer = TimerFactory.CreateNonCapturingTimer(
    state => Console.WriteLine("Timer ticked"),
    null,
    TimeSpan.FromSeconds(1),
    TimeSpan.FromSeconds(2));

Console.WriteLine("Timer started (1s delay, 2s interval)");
Thread.Sleep(5000);

Methods

Name Description
CreateNonCapturingTimer(TimerCallback, object, TimeSpan, TimeSpan)

Initializes a new instance of the Timer class that suppress capturing the ExecutionContext.