Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
STATaskInvoker.cs
Go to the documentation of this file.
1using System;
4
5namespace ReLogic.OS.Windows;
6
7internal class STATaskInvoker : IDisposable
8{
9 private static STATaskInvoker Instance;
10
12
13 private volatile bool _shouldThreadContinue;
14
16
17 private object _taskInvokeLock = new object();
18
19 private object _taskCompletionLock = new object();
20
21 private bool disposedValue;
22
24 {
27 _staThread.Name = "STA Invoker Thread";
30 }
31
32 public static void Invoke(Action action)
33 {
34 if (Instance == null)
35 {
37 }
38 Instance.InvokeAndWait(action);
39 }
40
41 public static T Invoke<T>(Func<T> action)
42 {
43 if (Instance == null)
44 {
46 }
47 T output = default(T);
48 Instance.InvokeAndWait(delegate
49 {
50 output = action();
51 });
52 return output;
53 }
54
55 private void InvokeAndWait(Action action)
56 {
57 lock (_taskInvokeLock)
58 {
60 {
63 }
64 }
65 }
66
67 private void TaskThreadStart()
68 {
70 {
71 Action action = _staTasks.Take();
73 {
74 action();
76 }
77 }
78 }
79
80 private void Shutdown()
81 {
82 InvokeAndWait(delegate
83 {
85 });
86 }
87
88 protected virtual void Dispose(bool disposing)
89 {
90 if (disposedValue)
91 {
92 return;
93 }
94 if (disposing)
95 {
96 Shutdown();
97 if (_staTasks != null)
98 {
100 _staTasks = null;
101 }
102 }
103 disposedValue = true;
104 }
105
106 public void Dispose()
107 {
108 Dispose(disposing: true);
109 }
110}
virtual void Dispose(bool disposing)
static void Invoke(Action action)
static STATaskInvoker Instance
static T Invoke< T >(Func< T > action)
BlockingCollection< Action > _staTasks
static bool Wait(object obj, int millisecondsTimeout)
Definition Monitor.cs:87
static void Pulse(object obj)
Definition Monitor.cs:103
void SetApartmentState(ApartmentState state)
Definition Thread.cs:771
void Start(object? parameter)
Definition Thread.cs:574