Repository navigation
EN CSharp Time
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
DateTime and DateTimeOffset describe the date and time, TimeSpan the interval, DateOnly/TimeOnly the individual parts. To measure duration, use Stopwatch; The system clock may change. The timer calls the code on a schedule and does not confirm game events.
Save this example separately as Example.cs. Run it independently of the other examples on this page.
Example.cs:
// PROJECT-EXAMPLE
var delay = System.TimeSpan.FromMilliseconds(10);
await System.Threading.Tasks.Task.Delay(delay);
System.Console.WriteLine("Done");Result:
Done
var started = System.Diagnostics.Stopwatch.StartNew();
await WaitAsync(100);
UO.Print($"Elapsed: {started.ElapsedMilliseconds} ms");DateTimeOffset now = DateTimeOffset.UtcNow;
TimeSpan interval = TimeSpan.FromSeconds(2);
UO.Print($"UTC: {now:O}; interval: {interval.TotalMilliseconds} ms");For periodic async wait there is PeriodicTimer. Release the timer when the script completes and transfer Cancellation to WaitForNextTickAsync. A pause in the script and the passage of real time are two different things.
Official documentation: Date, time, intervals and timers - Microsoft Learn.
ClassicUO — Bad Newbie & C# Scripts IDE