Caliburn.Micro always had the concept of Coroutines which allowed you to write asynchronous code in a synchronous way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
public class ScreenOneViewModel | |
{ | |
public IEnumerable<IResult> GoForward() | |
{ | |
yield return Loader.Show("Downloading..."); | |
yield return new LoadCatalog("Caliburn.Micro.Coroutines.External.xap"); | |
yield return Loader.Hide(); | |
yield return new ShowScreen("ExternalScreen"); | |
} | |
} |
Starting from .NET 4.5 with the introduction of the async and await keywords, Microsoft introduced the concept of Coroutines in the language itself.
So if you want to use the same code in Caliburn.Micro with the async syntax, it becomes:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
public class ScreenOneViewModel | |
{ | |
public async Task GoForward() | |
{ | |
await Loader.Show("Downloading..."); | |
await new LoadCatalog("Caliburn.Micro.Coroutines.External.xap").LoadAsync(); | |
await Loader.Hide(); | |
await ShowScreen("ExternalScreen"); | |
} | |
} | |
More information here: http://caraulean.com/blog/2013/07/15/using-caliburn-micro-with-async-await/