tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
ProgramShutdownTokenSource.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3
5{
10 {
14 readonly object tokenSourceAccessLock;
15
19 CancellationTokenSource? cancellationTokenSource;
20
24 public CancellationToken Token => cancellationTokenSource?.Token ?? default;
25
30 {
31 tokenSourceAccessLock = new object();
32 cancellationTokenSource = new CancellationTokenSource();
33
34 AppDomain.CurrentDomain.ProcessExit += (sender, args) =>
35 {
38 };
39
40 Console.CancelKeyPress += (sender, args) =>
41 {
42 args.Cancel = true;
45 };
46 }
47
49 public void Dispose()
50 {
52 {
53 cancellationTokenSource?.Dispose();
55 }
56 }
57 }
58}
Contains a CancellationToken that triggers when the operating system requests the program shuts down.
CancellationTokenSource? cancellationTokenSource
The CancellationTokenSource for the ProgramShutdownTokenSource.
readonly object tokenSourceAccessLock
Lock object for cancellationTokenSource.
ProgramShutdownTokenSource()
Initializes a new instance of the ProgramShutdownTokenSource class.