I've started learning some mobile development using Xamarin Forms and MvvmCross.
In its simplest form I have an app that contains a button. When this button is tapped it calls an api via a rest service and returns data via the messaging service.
I'm having issues showing dialogs (ACR) when using the ICommand.Execute(object) pattern. I'm assuming this is because the execute in this pattern is not async and therefore blocks the main ui thread? This is a sample of what I'm doing:
var cmd = Command.Create(CmdType.Login);
cmd.Execute(User);
Please consider the following lines straight from the MvvmCross documentation for async operations.
MyCommand = new MvxCommand(() => MyTaskNotifier = MvxNotifyTask.Create(() => MyMethodAsync(), onException: ex => OnException(ex)));
private async Task MyMethodAsync()
{
await _someService.DoSomethingAsync();
// ...
}
In this case my DoSomething() isn't aysnc - if anything its an async void, or a no no. To get around this I've updated from MvxCommand to MvxAsyncCommand and then have to use a bandaid to get the dialogs to show.
await Task.Delay(300);
or
await Task.Run(() => { command.Execute(User); }).ConfigureAwait(false);
At this point, I'm obviously questioning the use of the command pattern. Am I missing an easy fix or have I chosen an architecture that's not a good fit here? Any guidance is appreciated.