Skip to main content

Definition

Assembly: CloudNimble.BlazorEssentials.dll Namespace: CloudNimble.BlazorEssentials.Threading Inheritance: System.Object

Syntax

CloudNimble.BlazorEssentials.Threading.DelayDispatcher

Summary

Provides methods to reduce the number of events that are fired, usually so that rapid, imperceptible changes are ignored.

Remarks

Throttle() ensures that events are throttled by the interval specified. Only the last event in the interval sequence of events fires. Debounce() fires an event only after the specified interval has passed in which no other pending event has fired. Only the last event in the sequence is fired. Adapted from https://weblog.west-wind.com/posts/2017/Jul/02/Debouncing-and-Throttling-Dispatcher-Events.

Constructors

.ctor

Syntax

public DelayDispatcher()

.ctor Inherited

Inherited from object

Syntax

public Object()

Properties

DelayCount

The number of events that have been dropped in a given interval.

Syntax

public int DelayCount { get; internal set; }

Property Value

Type: int

Remarks

This value is reset every time the built-in Timer elapses.

TimerStarted

The DateTime that a new Timer was started, in UTC.

Syntax

public System.DateTime TimerStarted { get; internal set; }

Property Value

Type: System.DateTime

Methods

Debounce

Debounce an event by resetting the event timeout every time the event is fired. The behavior is that the Action passed is fired only after events stop firing for the given timeout period. Use Debounce when you want events to fire only after events stop firing after the given interval timeout period. Wrap the logic you would normally use in your event code into the Action you pass to this method to debounce the event. Example: https://gist.github.com/RickStrahl/0519b678f3294e27891f4d4f0608519a

Syntax

public void Debounce(int interval, System.Action<object> action, object param = null)

Parameters

NameTypeDescription
intervalintAn Int32 specifying the Timer duration (in milliseconds).
actionSystem.Action<object>The Action to fire when the Timer elapses.
paramobjectAny optional parameters to pass to the action.

Dispose

Syntax

public void Dispose()

Equals Inherited Virtual

Inherited from object

Syntax

public virtual bool Equals(object obj)

Parameters

NameTypeDescription
objobject?-

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

public static bool Equals(object objA, object objB)

Parameters

NameTypeDescription
objAobject?-
objBobject?-

Returns

Type: bool

GetHashCode Inherited Virtual

Inherited from object

Syntax

public virtual int GetHashCode()

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

public System.Type GetType()

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

protected internal object MemberwiseClone()

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

public static bool ReferenceEquals(object objA, object objB)

Parameters

NameTypeDescription
objAobject?-
objBobject?-

Returns

Type: bool

Throttle

This method throttles events by allowing only 1 event to fire for the given timeout period. Only the last event fired is handled - all others are ignored. Throttle will fire events every timeout ms even if additional events are pending. Use Throttle where you need to ensure that events fire at given intervals.

Syntax

public void Throttle(int interval, System.Action<object> action, object param = null)

Parameters

NameTypeDescription
intervalintAn Int32 specifying the Timer duration (in milliseconds).
actionSystem.Action<object>The Action to fire when the Timer elapses.
paramobjectAny optional parameters to pass to the action.

ToString Inherited Virtual

Inherited from object

Syntax

public virtual string ToString()

Returns

Type: string?
  • System.IDisposable