I am trying to create a MVVM Avalonia app using the ReactiveUi and want to execute a command async in order to keep the user interface working. However this is not the case. After hitting my button, the ui freezes until the command has finished executing even though i am running it async.
Does somebody know, what i am doing wrong here?
This is what i am currently doing:
ViewModel:
public LoginViewModel()
{
TryConnectAsyncCommand = ReactiveCommand.CreateFromTask(TryConnectAndLogin);
}
public ReactiveCommand<Unit, Unit> TryConnectAsyncCommand { get; }
async Task TryConnectAndLogin()
{
ErrorFlag = false;
ClientConversationManager.TryConnect(EnteredInstance, EnteredPort);
if (ClientConversationManager.IsConnected)
{
}
else
{
ErrorFlagContent = "Could not connect to server :/";
ErrorFlag = true;
}
}
View:
Command="{Binding TryConnectAsyncCommand}"
awaits in your function. Perhaps there should be something likeawait ClientConversationManager.TryConnectAsync(or similarTryConnectAndLogin?await. Marking itasyncdoesn't magically do anything until you have anawait