I\'m trying to analyse the usage of the UI thread. Is it possible to query the number of items queued by the dispatcher?
UPDATE: Clemens answer wor
Afaik there is no property or method where you can directly ask for the dispatcher queue length. You may however attach handlers to some of the DispatcherHooks events, provided by the Hooks property.
var queueLength = 0;
Dispatcher.Hooks.OperationPosted += (o, e) => Interlocked.Increment(ref queueLength);
Dispatcher.Hooks.OperationStarted += (o, e) => Interlocked.Decrement(ref queueLength);
Dispatcher.Hooks.OperationAborted += (o, e) => Interlocked.Decrement(ref queueLength);
If you are only interested in whether the Dispatcher is active or not, you might just handle the OperationPosted event in conjunction with DispatcherInactive.