ThreadThrottler Class
Namespace: Stride.CoreAssembly: Stride.Core.dll
public class ThreadThrottler
Name | Description | |
---|---|---|
Constructors | ||
ThreadThrottler() | Create an instance of this class without throttling and defaulting to Standard mode. See SetToPreciseAuto() and SetToPreciseManual(Int64) to set it to other modes. |
|
ThreadThrottler(Int32) | Create an instance of this class set to Standard mode. See SetToPreciseAuto() and SetToPreciseManual(Int64) to set it to other modes. |
|
ThreadThrottler(TimeSpan) | Create an instance of this class set to Standard mode. See SetToPreciseAuto() and SetToPreciseManual(Int64) to set it to other modes. |
|
Properties | ||
MinimumElapsedTime | Set this to zero to disable throttling. Minimum amount of time allowed between each 'update'. Conversion is lossy, getting this value back might not return the same value you set it to. |
|
Type | The type of throttler used |
|
Methods | ||
SetMaxFrequency(Int32) | Thread will be blocked to stay within the given amount of 'updates' per second. |
|
SetToPreciseAuto() | Most of the timings will be perfectly precise to the system timer at the cost of higher CPU usage. If you aren't sure, use SetToStandard() instead. |
|
SetToPreciseManual(Int64) | Depending on the provided value, timings will be perfectly precise to the system timer at the cost of higher CPU usage. If you aren't sure, use SetToStandard() instead. |
|
SetToStandard() | Saves CPU cycles while waiting, this one is the least precise mode but the lightest. If you aren't sure, use this one ! |
|
Throttle(out Double) | Forces the thread to sleep when the time elapsed since last call is lower than MinimumElapsedTime, it will sleep for the time remaining to reach MinimumElapsedTime. Use this function inside a loop when you want to lock it to a specific rate. |
|
Throttle(out Int64) | Forces the thread to sleep when the time elapsed since last call is lower than MinimumElapsedTime, it will sleep for the time remaining to reach that value. Use this function inside a loop when you want to lock it to a specific rate. |
|
Throttle(out TimeSpan) | Forces the thread to sleep when the time elapsed since last call is lower than MinimumElapsedTime, it will sleep for the time remaining to reach MinimumElapsedTime. Use this function inside a loop when you want to lock it to a specific rate. |
Constructors
ThreadThrottler()
Create an instance of this class without throttling and defaulting to Standard mode. See SetToPreciseAuto() and SetToPreciseManual(Int64) to set it to other modes.
public ThreadThrottler()
ThreadThrottler(Int32)
Create an instance of this class set to Standard mode. See SetToPreciseAuto() and SetToPreciseManual(Int64) to set it to other modes.
public ThreadThrottler(int frequencyMax)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | frequencyMax | The maximum frequency this object allows |
ThreadThrottler(TimeSpan)
Create an instance of this class set to Standard mode. See SetToPreciseAuto() and SetToPreciseManual(Int64) to set it to other modes.
public ThreadThrottler(TimeSpan minimumElapsedTimeParam)
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | minimumElapsedTimeParam | Minimum time allowed between each call |
Properties
MinimumElapsedTime
Set this to zero to disable throttling. Minimum amount of time allowed between each 'update'. Conversion is lossy, getting this value back might not return the same value you set it to.
public TimeSpan MinimumElapsedTime { get; set; }
Property Value
Type | Description |
---|---|
System.TimeSpan |
Remarks
See Throttle(out Int64)'s summary for an idea of how this property is used.
Type
The type of throttler used
public ThreadThrottler.ThrottlerType Type { get; }
Property Value
Type | Description |
---|---|
ThreadThrottler.ThrottlerType |
Methods
SetMaxFrequency(Int32)
Thread will be blocked to stay within the given amount of 'updates' per second.
public void SetMaxFrequency(int frequencyMax)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | frequencyMax |
Remarks
It effectively transforms the given parameter from frame per second to the internal closest second per frame equivalent for it.
SetToPreciseAuto()
Most of the timings will be perfectly precise to the system timer at the cost of higher CPU usage.
If you aren't sure, use SetToStandard() instead.
public void SetToPreciseAuto()
Remarks
This mode uses and automatically scales a spinwait window based on system responsiveness to find the right balance between Thread.Sleep calls and spinwaiting.
SetToPreciseManual(Int64)
Depending on the provided value, timings will be perfectly precise to the system timer at the cost of higher CPU usage.
If you aren't sure, use SetToStandard() instead.
public void SetToPreciseManual(long spinwaitWindowParam)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | spinwaitWindowParam |
Remarks
This mode uses the given value as the duration of the spinwait window. The format of this value is based on System.Diagnostics.Stopwatch.System.Diagnostics.Stopwatch.Frequency
SetToStandard()
Saves CPU cycles while waiting, this one is the least precise mode but the lightest.
If you aren't sure, use this one !
public void SetToStandard()
Throttle(out Double)
Forces the thread to sleep when the time elapsed since last call is lower than MinimumElapsedTime, it will sleep for the time remaining to reach MinimumElapsedTime.
Use this function inside a loop when you want to lock it to a specific rate.
public bool Throttle(out double elapsedInSeconds)
Parameters
Type | Name | Description |
---|---|---|
System.Double | elapsedInSeconds | The time since the last call in seconds, returns a value close to MinimumElapsedTime, use this value as your delta time. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Throttle(out Int64)
Forces the thread to sleep when the time elapsed since last call is lower than MinimumElapsedTime, it will sleep for the time remaining to reach that value.
Use this function inside a loop when you want to lock it to a specific rate.
public bool Throttle(out long elapsedInSwFreq)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | elapsedInSwFreq | The time since the last call in System.Diagnostics.Stopwatch.System.Diagnostics.Stopwatch.Frequency returns a value close to MinimumElapsedTime, use this value as your delta time. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Throttle(out TimeSpan)
Forces the thread to sleep when the time elapsed since last call is lower than MinimumElapsedTime, it will sleep for the time remaining to reach MinimumElapsedTime.
Use this function inside a loop when you want to lock it to a specific rate.
public bool Throttle(out TimeSpan elapsedTimeSpan)
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | elapsedTimeSpan | The time since the last call, returns a value close to MinimumElapsedTime, use this value as your delta time. |
Returns
Type | Description |
---|---|
System.Boolean |
|