Button Click Queued On Dispatcher
When I click a button in wpf, is it the mouse click or the button click event that gets queued onto the disp开发者_JAVA百科atcher? Is there a way to prove this?
This is currently what I'm doing to check all the posted operations. But I can't tell if the operation came from mouse move event/backgroundthread/etc.
Application.Current.Dispatcher.Hooks.OperationPosted += (sender, e) =>
{
var operation = e.Operation;
};
The event will be invoked in the context of the dispatcher.
You can check this by reading SynchronizationContext.Current
. It will be an instance of DispatcherSynchronizationContext
whenever you are in a dispatcher context.
精彩评论