Table of Contents

Class BlockingTimer

Namespace
Hi.Common
Assembly
HiGeom.dll

Timer use one task and delay each event call. The delay time is Period, counted from the previous trigger to the nest trigger. The first function call does no intending delay. If the execution time is over the Period, no delay between the triggers.

public class BlockingTimer : IMakeXmlSource, IDisposable
Inheritance
BlockingTimer
Implements
Inherited Members
Extension Methods

Constructors

BlockingTimer()

Ctor.

public BlockingTimer()

BlockingTimer(TimeSpan)

Initializes a new instance of the BlockingTimer class with the specified period.

public BlockingTimer(TimeSpan period)

Parameters

period TimeSpan

The time interval between timer events

BlockingTimer(XElement)

Constructor that initializes the timer from XML data.

public BlockingTimer(XElement src)

Parameters

src XElement

XML element containing timer configuration

Fields

XName

XML element name for serialization.

public static string XName

Field Value

string

Properties

Period

The time period between timer events.

public TimeSpan Period { get; set; }

Property Value

TimeSpan

WorkingTask

Gets the task that represents the timer's working process.

public Task WorkingTask { get; }

Property Value

Task

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

EnsureRunOnce()

Ensures the timer runs at least once.

public Task EnsureRunOnce()

Returns

Task

The task representing the timer's working process

MakeXmlSource(string, string)

Creates an XML representation of the object. This method may also generate additional resources such as related files.

public XElement MakeXmlSource(string baseDirectory, string relFile)

Parameters

baseDirectory string

The base directory for resolving relative paths

relFile string

The relative file path for the XML source

Returns

XElement

An XML element representing the object's state

Remarks

For the demand of easy moving source folder (especially project folder) without configuration file path corruption, the relative file path is applied. The baseDirectory is typically the folder at the nearest configuration file folder. Since the folder can be moving with the configuration file.

Start()

Starts the timer in long-term mode.

public Task Start()

Returns

Task

The task representing the timer's working process

Stop()

Stops the timer and cancels any ongoing operations.

public Task Stop()

Returns

Task

The task representing the timer's working process

Events

Elapsed

Event that is triggered when the timer elapses.

public event Action<CancellationToken> Elapsed

Event Type

Action<CancellationToken>