Preventing concurrent RelayCommand executions throughout a ViewModel #548
Unanswered
symbiogenesis
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I make extensive use of RelayCommand and AsyncRelayCommand.
I was noticing that sometimes concurrent executions could happen in my code, not just of the same command, and I wanted to prevent that.
All my ViewModels inherit from a BaseViewModel which has a boolean IsBusy property. And my default boilerplate pattern at the moment is to wrap all of my command logic in a try-catch-finally that initially sets IsBusy to true, and then sets it to false in the finally block. Then all my canExecute routines include a check that IsBusy is false.
I later noticed that there was an option, AsyncRelayCommandOptions.AllowConcurrentExecutions. Which of course made me figure that the default behavior is not to allow them, which seems to only prevent a single command from concurrently executing. But I would like all commands to happen one at a time.
This pattern that I'm using is adequate, and it prevents this problem in a single ViewModel, but it would be kind of neat if there were a way to more concisely accomplish what I'm after, and I'm sure that it is a very common desire.
Or perhaps my entire logic is misguided
Beta Was this translation helpful? Give feedback.
All reactions