Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AsyncActionDispatcher.cs
Go to the documentation of this file.
1using System;
5
7
9{
11
13
15
16 private volatile bool _isRunning;
17
19
20 public bool IsDisposed { get; private set; }
21
22 public bool IsRunning => _isRunning;
23
24 public void Queue(Action action)
25 {
27 }
28
29 public void Start()
30 {
31 if (IsRunning)
32 {
33 throw new InvalidOperationException("AsyncActionDispatcher is already started.");
34 }
35 _isRunning = true;
37 {
38 IsBackground = true,
39 Name = "AsyncActionDispatcher Thread"
40 };
42 }
43
44 public void Stop()
45 {
46 if (!IsRunning)
47 {
48 throw new InvalidOperationException("AsyncActionDispatcher is already stopped.");
49 }
50 _isRunning = false;
53 }
54
55 [DebuggerNonUserCode]
56 private void LoaderThreadStart()
57 {
58 while (_isRunning)
59 {
60 try
61 {
63 }
65 {
66 break;
67 }
68 }
69 }
70
71 protected virtual void Dispose(bool disposing)
72 {
73 if (IsDisposed)
74 {
75 return;
76 }
77 if (disposing)
78 {
79 if (IsRunning)
80 {
81 Stop();
82 }
85 }
86 IsDisposed = true;
87 }
88
89 public void Dispose()
90 {
91 Dispose(disposing: true);
92 }
93}
readonly CancellationTokenSource _threadCancellation
readonly BlockingCollection< Action > _actionQueue
bool Join(int millisecondsTimeout)
void Start(object? parameter)
Definition Thread.cs:574