Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ProcessThread.cs
Go to the documentation of this file.
4
5namespace System.Diagnostics;
6
7[Designer("System.Diagnostics.Design.ProcessThreadDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
8public class ProcessThread : Component
9{
10 private enum State
11 {
12 IsLocal = 2
13 }
14
15 private readonly bool _isRemoteMachine;
16
17 private readonly int _processId;
18
19 private readonly ThreadInfo _threadInfo;
20
21 private bool? _priorityBoostEnabled;
22
24
26
28
29 public int Id => (int)_threadInfo._threadId;
30
32 {
33 get
34 {
35 if (!_priorityBoostEnabled.HasValue)
36 {
38 }
39 return _priorityBoostEnabled.Value;
40 }
41 set
42 {
45 }
46 }
47
49 {
50 [SupportedOSPlatform("windows")]
51 [SupportedOSPlatform("linux")]
52 [SupportedOSPlatform("freebsd")]
53 get
54 {
55 if (!_priorityLevel.HasValue)
56 {
58 }
59 return _priorityLevel.Value;
60 }
61 [SupportedOSPlatform("windows")]
62 set
63 {
66 }
67 }
68
70
72
74 {
75 get
76 {
78 {
80 }
82 }
83 }
84
85 [SupportedOSPlatform("windows")]
86 [SupportedOSPlatform("linux")]
88
89 public int IdealProcessor
90 {
91 set
92 {
94 if (global::Interop.Kernel32.SetThreadIdealProcessor(handle, value) < 0)
95 {
96 throw new Win32Exception();
97 }
98 }
99 }
100
102 {
103 get
104 {
106 if (!global::Interop.Kernel32.GetThreadPriorityBoost(handle, out var disabled))
107 {
108 throw new Win32Exception();
109 }
110 return !disabled;
111 }
112 set
113 {
115 if (!global::Interop.Kernel32.SetThreadPriorityBoost(handle, !value))
116 {
117 throw new Win32Exception();
118 }
119 }
120 }
121
123 {
124 get
125 {
127 int threadPriority = global::Interop.Kernel32.GetThreadPriority(handle);
128 if (threadPriority == int.MaxValue)
129 {
130 throw new Win32Exception();
131 }
132 return (ThreadPriorityLevel)threadPriority;
133 }
134 set
135 {
137 if (!global::Interop.Kernel32.SetThreadPriority(handle, (int)value))
138 {
139 throw new Win32Exception();
140 }
141 }
142 }
143
144 [SupportedOSPlatform("windows")]
146 {
147 set
148 {
150 if (global::Interop.Kernel32.SetThreadAffinityMask(handle, value) == IntPtr.Zero)
151 {
152 throw new Win32Exception();
153 }
154 }
155 }
156
158
160
162
163 internal ProcessThread(bool isRemoteMachine, int processId, ThreadInfo threadInfo)
164 {
165 _isRemoteMachine = isRemoteMachine;
166 _processId = processId;
167 _threadInfo = threadInfo;
168 }
169
170 private void EnsureState(State state)
171 {
172 if ((state & State.IsLocal) != 0 && _isRemoteMachine)
173 {
175 }
176 }
177
179 {
180 int idealProcessor = ((IntPtr.Size == 4) ? 32 : 64);
181 IdealProcessor = idealProcessor;
182 }
183
185 {
186 return GetThreadTimes().StartTime;
187 }
188
190 {
192 ProcessThreadTimes processThreadTimes = new ProcessThreadTimes();
193 if (!global::Interop.Kernel32.GetThreadTimes(handle, out processThreadTimes._create, out processThreadTimes._exit, out processThreadTimes._kernel, out processThreadTimes._user))
194 {
195 throw new Win32Exception();
196 }
197 return processThreadTimes;
198 }
199
201 {
202 EnsureState(State.IsLocal);
203 return ProcessManager.OpenThread((int)_threadInfo._threadId, access);
204 }
205}
static SafeThreadHandle OpenThread(int threadId, int access)
ProcessThread(bool isRemoteMachine, int processId, ThreadInfo threadInfo)
ThreadPriorityLevel PriorityLevel
ThreadPriorityLevel? _priorityLevel
ThreadPriorityLevel PriorityLevelCore
readonly ThreadInfo _threadInfo
ProcessThreadTimes GetThreadTimes()
SafeThreadHandle OpenThreadHandle(int access)
ThreadWaitReason _threadWaitReason
Definition ThreadInfo.cs:17
static string WaitReasonUnavailable
Definition SR.cs:40
static string NotSupportedRemoteThread
Definition SR.cs:42
Definition SR.cs:7
static readonly IntPtr Zero
Definition IntPtr.cs:18