Class DelayProvider
Represents logic providing several delay mechanisms.
Implements
Inherited Members
Namespace: Swan.Threading
Syntax
public sealed class DelayProvider : IDisposable
Examples
The following example shows how to implement delay mechanisms.
using Swan.Threading;
public class Example
{
public static void Main()
{
// using the ThreadSleep strategy
using (var delay = new DelayProvider(DelayProvider.DelayStrategy.ThreadSleep))
{
// retrieve how much time was delayed
var time = delay.WaitOne();
}
}
}
Constructors
DelayProvider(DelayProvider.DelayStrategy)
Initializes a new instance of the DelayProvider class.
Declaration
public DelayProvider(DelayProvider.DelayStrategy strategy = DelayProvider.DelayStrategy.TaskDelay)
Parameters
Type | Name | Description |
---|---|---|
DelayProvider.DelayStrategy | strategy | The strategy. |
Properties
Strategy
Gets the selected delay strategy.
Declaration
public DelayProvider.DelayStrategy Strategy { get; }
Property Value
Type | Description |
---|---|
DelayProvider.DelayStrategy |
Methods
Dispose()
Declaration
public void Dispose()
WaitOne()
Creates the smallest possible, synchronous delay based on the selected strategy.
Declaration
public TimeSpan WaitOne()
Returns
Type | Description |
---|---|
TimeSpan | The elapsed time of the delay. |