4
UI 스레드의 사용법을 분석하려고합니다. 발송자가 대기중인 항목 수를 쿼리 할 수 있습니까?Dispatcher 큐 길이 쿼리
UPDATE는 : 클레멘스 대답은 ... UI를 시작하고 난 단지 초당 나는 다음과 같은 코드를 사용하면 데이터를 샘플링 걱정 후에 나는이 킥오프 싶어하지만 같이 완벽하게 작동
int queueLength = 0;
var currentDispatcher = Dispatcher.CurrentDispatcher;
currentDispatcher.Hooks.OperationPosted += (s, e) => Interlocked.Increment(ref queueLength);
currentDispatcher.Hooks.OperationCompleted += (s, e) => Interlocked.Decrement(ref queueLength);
currentDispatcher.Hooks.OperationAborted += (s, e) => Interlocked.Decrement(ref queueLength);
Observable
.Interval(TimeSpan.FromSeconds(1))
.Subscribe(x =>
{
int currentQueueLength = queueLength;
if (currentQueueLength < 0)
{
Interlocked.Add(ref queueLength, currentQueueLength * -1);
}
UiQueueLength = queueLength;
});