Dreamine.Logging.Wpf
1.0.2
Dreamine.Logging.Wpf 사용자 인터페이스 기능과 구성 요소를 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
BatchedDispatcher.cs
이 파일의 문서화 페이지로 가기
1
using
System;
2
using
System.Collections.Concurrent;
3
using
System.Collections.Generic;
4
using
System.Threading;
5
using
System.Windows.Threading;
6
7
namespace
Dreamine.Logging.Wpf.Services
8
{
33
public
sealed
class
BatchedDispatcher
<T>
34
{
43
public
const
int
MaxBatchSize
= 256;
44
53
private
readonly Dispatcher
_dispatcher
;
62
private
readonly Action<IReadOnlyList<T>>
_onBatch
;
71
private
readonly DispatcherPriority
_priority
;
80
private
readonly ConcurrentQueue<T>
_pending
=
new
();
89
private
int
_scheduled
;
90
131
public
BatchedDispatcher
(
132
Dispatcher dispatcher,
133
Action<IReadOnlyList<T>> onBatch,
134
DispatcherPriority priority = DispatcherPriority.Background)
135
{
136
_dispatcher
= dispatcher ??
throw
new
ArgumentNullException(nameof(dispatcher));
137
_onBatch
= onBatch ??
throw
new
ArgumentNullException(nameof(onBatch));
138
_priority
= priority;
139
}
140
157
public
void
Enqueue
(T item)
158
{
159
_pending
.Enqueue(item);
160
ScheduleFlushIfNeeded
();
161
}
162
171
private
void
ScheduleFlushIfNeeded
()
172
{
173
// Ensure only one DispatcherOperation is pending at any time.
174
if
(Interlocked.CompareExchange(ref
_scheduled
, 1, 0) != 0)
175
{
176
return
;
177
}
178
179
_dispatcher
.BeginInvoke(
_priority
,
new
Action(
Flush
));
180
}
181
190
private
void
Flush
()
191
{
192
try
193
{
194
var buffer =
new
List<T>(Math.Min(
_pending
.Count,
MaxBatchSize
));
195
196
while
(buffer.Count <
MaxBatchSize
&&
_pending
.TryDequeue(out var item))
197
{
198
buffer.Add(item);
199
}
200
201
if
(buffer.Count > 0)
202
{
203
_onBatch
(buffer);
204
}
205
}
206
finally
207
{
208
Volatile.Write(ref
_scheduled
, 0);
209
210
// Re-arm if producers added more while we were running.
211
if
(!
_pending
.IsEmpty)
212
{
213
ScheduleFlushIfNeeded
();
214
}
215
}
216
}
217
}
218
}
Dreamine.Logging.Wpf.Services
Definition
BatchedDispatcher.cs:8
Dreamine.Logging.Wpf.Services.BatchedDispatcher-1-g._pending
readonly ConcurrentQueue< T > _pending
Definition
BatchedDispatcher.cs:80
Dreamine.Logging.Wpf.Services.BatchedDispatcher-1-g._dispatcher
readonly Dispatcher _dispatcher
Definition
BatchedDispatcher.cs:53
Dreamine.Logging.Wpf.Services.BatchedDispatcher-1-g.Flush
void Flush()
Definition
BatchedDispatcher.cs:190
Dreamine.Logging.Wpf.Services.BatchedDispatcher-1-g.MaxBatchSize
const int MaxBatchSize
Definition
BatchedDispatcher.cs:43
Dreamine.Logging.Wpf.Services.BatchedDispatcher-1-g._scheduled
int _scheduled
Definition
BatchedDispatcher.cs:89
Dreamine.Logging.Wpf.Services.BatchedDispatcher-1-g.BatchedDispatcher
BatchedDispatcher(Dispatcher dispatcher, Action< IReadOnlyList< T > > onBatch, DispatcherPriority priority=DispatcherPriority.Background)
Definition
BatchedDispatcher.cs:131
Dreamine.Logging.Wpf.Services.BatchedDispatcher-1-g._priority
readonly DispatcherPriority _priority
Definition
BatchedDispatcher.cs:71
Dreamine.Logging.Wpf.Services.BatchedDispatcher-1-g.Enqueue
void Enqueue(T item)
Definition
BatchedDispatcher.cs:157
Dreamine.Logging.Wpf.Services.BatchedDispatcher-1-g.ScheduleFlushIfNeeded
void ScheduleFlushIfNeeded()
Definition
BatchedDispatcher.cs:171
Dreamine.Logging.Wpf.Services.BatchedDispatcher-1-g._onBatch
readonly Action< IReadOnlyList< T > > _onBatch
Definition
BatchedDispatcher.cs:62
Services
BatchedDispatcher.cs
다음에 의해 생성됨 :
1.17.0