Will caliburn.micro work correctly with the async method on ViewModel?

As already mentioned, the new .NET async / await model spreads through software layers such as a virus. A recent change in async has now bounced to my view model, and I wonder if the change declaration is safe from public void DoStuff() to public async Task DoStuff() ?

Thanks!

+4
source share
3 answers

Support for the asynchronous programming model in Caliburn.Micro is now very good.

A few things you can do:

  • Use async / await in an action method . Be careful, since action methods are technically event handlers, you are shoud do async void , not async Task .
  • Asynchronous event handlers for screen events , for example, Activated, ViewLoaded, and others.
  • Asynchronous overrides for screen methods : OnInitialize, OnActivate, ... You can then override it as protected override async void OnInitialize(){} , and inside you can wait for another task.
  • Convert Coroutines to Tasks . Use the ExecuteAsync() extension method. In some scenarios, Coroutines has some advantages, such as an execution context.
  • IHandleWithTask<TMessage> - quite convenient ...

There 's a blog post describing some use cases , with a few snippets of code. And the GitHub repository with a sample project I played with asynchronous / wait in Caliberna.

+15
source

The answer is yes, starting with Caliburn.Micro 1.5.

See the release announcement .

+2
source

Marco Amendola , project manager for the Caliburn.Micro project, wrote an article that says : Coroutines are dead. Long live the Coroutines. And he called it that way because of the emergence of the asynchronous wait and wait programming model, and if you read the article, you will see that asynchronous / wait comes to life that you did in Coroutines in the past, so I assume you can safely use them where used to be Coroutines. I advise you to read the article.

+1
source

Source: https://habr.com/ru/post/1469333/


All Articles