In fact, data binding requires INotifyPropertyChanged.PropertyChanged , created in the context of user interface synchronization.
async / await forces you to distinguish between properties (which represent the current state and are always synchronous) and commands (which represent actions and can be synchronous or asynchronous). Property and property setters cannot be async , so your sample code with "asynchronous typing" is not possible.
async includes asynchronous commands. You can use command binding to asynchronously manage routed commands, or pass the async delegate to the DelegateCommand or use your own implementation of ICommand . Whichever way you do this, you will get an async void event handler.
A realistic example is that the properties of a virtual machine set the properties of M in memory and have SaveCommand with an async handler. Typically, async handlers interact with an additional VM property ( SaveInProgress or possibly shared Busy with other async handlers), so that the user interface can respond appropriately when the command is executed (typically at least causing CanExecute return false ).
So your async handler looks something like this:
private async void SaveCommandExecute() { try {
Note that the VM properties ( Error and Busy ) are updated in the context of the captured user interface.
This illustrates the central concept of async MVVM: commands can be async , but properties (such as Busy ) always represent the current state.
If you add async to an existing MVVM application, you will find that you have several additional properties that indicate a business, as well as possibly updating progress (for example, the percentage is complete). Depending on your application, you can perform several asynchronous operations at the same time. You need to think about good ways to add this information to your ideas; I believe this is the most difficult part of async MVVM applications.
Stephen cleary
source share