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