The Timer class is a static class that manages timer events for a script.
public static class TimerRemarks
The time the event is generated is guaranteed to be no less than the given duration, but may be more depending on system load.
Members at a glance
| Kind | Members |
|---|---|
| Methods | Cancel · Create |
Methods
Cancel
[System.Obsolete("Named timers are deprecated. Use the IEventSubscription returned from Timer.Create to cancel a timer.", false)]
public static void Cancel(string name)Cancels a repeating timer.
| Parameter | Type | Description |
|---|---|---|
name | string | Name of the timer to cancel. |
Remarks
If no timer with the given name exists, a ArgumentException will be thrown by the invocation.
Create
public static IEventSubscription Create(
double initialDurationSeconds,
Action handler
)Generates a one time event.
| Parameter | Type | Description |
|---|---|---|
initialDurationSeconds | double | The minimum duration to elapse before the event is generated in seconds. |
handler | Action | The Action to be called when the time has elapsed. |
Returns: IEventSubscription
public static IEventSubscription Create(
TimeSpan initialDuration,
Action handler
)Generates a one time event.
| Parameter | Type | Description |
|---|---|---|
initialDuration | TimeSpan | The minimum duration to elapse before the event is generated. |
handler | Action | The Action to be called when the time has elapsed. |
Returns: IEventSubscription
public static IEventSubscription Create(
double initialDurationSeconds,
Action handler,
bool persistent
)Generates a one time event.
| Parameter | Type | Description |
|---|---|---|
initialDurationSeconds | double | The minimum duration to elapse before the event is generated in seconds. |
handler | Action | The Action to be called when the time has elapsed. |
persistent | bool | Set to true to continue generating events, false to stop after the first one |
Returns: IEventSubscription
public static IEventSubscription Create(
double initialDurationSeconds,
double repeatDurationSeconds,
Action handler
)Generates a repeating event with an initial duration and a repeat duration.
| Parameter | Type | Description |
|---|---|---|
initialDurationSeconds | double | The minimum duration to elapse before the event is generated in seconds. |
repeatDurationSeconds | double | After the initial duration, events will be generated at this interval in seconds. |
handler | Action | The Action to be called when the time has elapsed. |
Returns: IEventSubscription
public static IEventSubscription Create(
TimeSpan initialDuration,
Action handler,
bool persistent
)Generates a one time event.
| Parameter | Type | Description |
|---|---|---|
initialDuration | TimeSpan | The minimum duration to elapse before the event is generated. |
handler | Action | The Action to be called when the time has elapsed. |
persistent | bool | Set to true to continue generating events, false to stop after the first one |
Returns: IEventSubscription
public static IEventSubscription Create(
TimeSpan initialDuration,
TimeSpan repeatDuration,
Action handler
)Generates a repeating event with an initial duration and a repeat duration.
| Parameter | Type | Description |
|---|---|---|
initialDuration | TimeSpan | The minimum duration to elapse before the event is generated. |
repeatDuration | TimeSpan | After the initial duration, events will be generated at this interval. |
handler | Action | The Action to be called when the time has elapsed. |
Returns: IEventSubscription
[System.Obsolete("Named timers are deprecated. Use the IEventSubscription returned from Timer.Create to cancel a timer.", false)]
public static void Create(
TimeSpan initialDuration,
TimeSpan repeatDuration,
Action handler,
string name
)Generates a repeating event with an initial duration and a repeat duration. The event will continue as long as the script is active or until Timer.Cancel is called.
| Parameter | Type | Description |
|---|---|---|
initialDuration | TimeSpan | The minimum duration to elapse before the event is generated. |
repeatDuration | TimeSpan | After the initial duration, events will be generated at this interval. |
handler | Action | The Action to be called when the time has elapsed. |
name | string | A short string to identify this Timer. |
Remarks
At most, one event will be generated per server frame, even if the duration is significantly shorter than the server frame time. Only the first 8 characters of the name are significant. Multiple timers with the same name are allowed. When Timer.Cancel is called the first timer with a matching name is stopped.
Used in examples
- BanHammerExample.cs
- ScriptLibrary/Quest/QuestObjectInteraction.cs
- ScriptLibrary/Quest/QuestObjectTrigger.cs
- ScriptLibrary/Scene/HintText.cs
- ScriptLibrary/Scene/Screenshot.cs
- ScriptLibrary/Scene/Targeting.cs
- ScriptLibrary/Scene/TimeCountdown.cs
- ScriptLibrary/Scene/TimedEvents.cs
- ScriptLibrary/ScriptWatcher.cs
- SharedStopwatchExample.cs
- SharedStopwatchReaderExample.cs
- TwitchEventExample.cs
Generated from the Sansar 47.10.0 client ScriptApi snapshot.