Dreamine.Threading.Windows 1.0.1
이 패키지는 다른 어셈블리에서 `DMContainer`를 partial class로 확장하지 않습니다. 등록은 별도의 Registration 클래스를 통해 제공합니다.
로딩중...
검색중...
일치하는것 없음
WindowsTimerResolutionService.cs
이 파일의 문서화 페이지로 가기
1using Dreamine.Threading.Interfaces;
3
5
14public sealed class WindowsTimerResolutionService : ITimerResolutionService, IDisposable
15{
24 private readonly object _syncRoot = new();
33 private readonly uint _period;
42 private int _referenceCount;
51 private bool _disposed;
52
62 : this(1)
63 {
64 }
65
83 {
84 _period = period == 0 ? 1 : period;
85 }
86
119 public void Begin()
120 {
121 lock (_syncRoot)
122 {
124
125 if (_referenceCount == 0)
126 {
127 WinMmNativeMethods.timeBeginPeriod(_period);
128 }
129
131 }
132 }
133
158 public void End()
159 {
160 lock (_syncRoot)
161 {
162 if (_disposed)
163 {
164 return;
165 }
166
167 if (_referenceCount <= 0)
168 {
169 return;
170 }
171
173
174 if (_referenceCount == 0)
175 {
176 WinMmNativeMethods.timeEndPeriod(_period);
177 }
178 }
179 }
180
197 public void Dispose()
198 {
199 lock (_syncRoot)
200 {
201 if (_disposed)
202 {
203 return;
204 }
205
206 while (_referenceCount > 0)
207 {
208 WinMmNativeMethods.timeEndPeriod(_period);
210 }
211
212 _disposed = true;
213 }
214 }
215
232 private void ThrowIfDisposed()
233 {
234 if (_disposed)
235 {
236 throw new ObjectDisposedException(nameof(WindowsTimerResolutionService));
237 }
238 }
239}