I'm trying to implement a highly responsive UI for my MVVM application, so I've chosen to have all command handlers automatically execute in a BackgroundWorker
so they don't block the UI.
But at the same time, I don't want the user to be able to execute the same command while it is still executing in the background. The solution seems obvious:
- When
Executed
handler is invoked, have theCanExecute
handler returnfalse
- Start the
BackgroundWorker
async - When
BackgroundWorker
finishes, have theCanExecute
handler returntrue
again.
Problem is, I need to notify WPF after step 1 and again after step 3 that CanExecute
has changed and that it should be required. I know I can do it by calling CommandManager.InvalidateRequerySuggested
, but that causes CanExecute
handlers of all other commands to be requeried as well. Having a lot of commands, that's not good.
Is there a way to ask for requery of a specific command - i.e. the one that is currently being executed?
TIA