Struct SpinWait
Provides support for spin-based waiting.
Inherited Members
Namespace: Cqrs.Infrastructure
Assembly: Cqrs.dll
Syntax
[HostProtection(SecurityAction.LinkDemand, ExternalThreading = true, Synchronization = true)]
public struct SpinWait
Fields
DefaultSleepInMilliseconds
A recommended sleep value of 50.
Declaration
public const short DefaultSleepInMilliseconds = 50
Field Value
Type | Description |
---|---|
System.Int16 |
Properties
NextSpinWillYield
Gets whether the next call to System.Threading.SpinWait.SpinOnce will yield the processor, triggering a forced context switch.
Declaration
public bool NextSpinWillYield { get; }
Property Value
Type | Description |
---|---|
System.Boolean | Whether the next call to System.Threading.SpinWait.SpinOnce will yield the processor, triggering a forced context switch. |
Methods
Reset()
Resets the spin counter.
Declaration
public void Reset()
SpinOnce(Int16)
Performs a single spin.
Declaration
public void SpinOnce(short sleepInMilliseconds = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int16 | sleepInMilliseconds | The amount of milliseconds the thread will sleep for. |
SpinUntil(Func<Boolean>, Int16)
Spins until the specified condition is satisfied.
Declaration
public static void SpinUntil(Func<bool> condition, short sleepInMilliseconds = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Boolean> | condition | A delegate to be executed over and over until it returns true. |
System.Int16 | sleepInMilliseconds | The amount of milliseconds the thread will sleep for. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
SpinUntil(Func<Boolean>, Int32, Int16)
Spins until the specified condition is satisfied or until the specified timeout is expired.
Declaration
public static bool SpinUntil(Func<bool> condition, int millisecondsTimeout, short sleepInMilliseconds = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Boolean> | condition | A delegate to be executed over and over until it returns true. |
System.Int32 | millisecondsTimeout | The number of milliseconds to wait, or System.Threading.Timeout.Infinite (-1) to wait indefinitely. |
System.Int16 | sleepInMilliseconds | The amount of milliseconds the thread will sleep for. |
Returns
Type | Description |
---|---|
System.Boolean | True if the condition is satisfied within the timeout; otherwise, false |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentOutOfRangeException |
|
SpinUntil(Func<Boolean>, TimeSpan, Int16)
Spins until the specified condition is satisfied or until the specified timeout is expired.
Declaration
public static bool SpinUntil(Func<bool> condition, TimeSpan timeout, short sleepInMilliseconds = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Boolean> | condition | A delegate to be executed over and over until it returns true. |
System.TimeSpan | timeout | A System.TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely. |
System.Int16 | sleepInMilliseconds | The amount of milliseconds the thread will sleep for. |
Returns
Type | Description |
---|---|
System.Boolean | True if the condition is satisfied within the timeout; otherwise, false |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The |
System.ArgumentOutOfRangeException |
|