Ha Doan
Ha Doan

Reputation: 671

Xamarin QuickCross How to use Async command

I use QuickCross as MVVM framework for my project: https://github.com/MacawNL/QuickCross As guide, I create a command as

public RelayCommand RegisterCommand /* Data-bindable command that calls Register(), generated with cmd snippet. Keep on one line - see http://goo.gl/Yg6QMd for why. */ { get { if (_RegisterCommand == null) _RegisterCommand = new RelayCommand(Register); return _RegisterCommand; } } private RelayCommand _RegisterCommand; public const string COMMANDNAME_RegisterCommand = "RegisterCommand";

    private void Register()
    {
        //TODO: Check valid model

        var request = new RegistrationRequest
        {
            FullName = FullName,
            UserEmail = Email,
            Password = Password,
            UserType = UserType
        };
        var response =  userClientApi.Register(request);

        if (response.Succeed)
        {
            //TODO: handle success data
        }
    }

I work great, but I create a ASYNC function: RegisterAsync. How can I call async method in RelayCommand as following:

var response = await userClientApi.RegisterAsync(request);

Thank you for reading.

Upvotes: 0

Views: 437

Answers (1)

Miha Markic
Miha Markic

Reputation: 3240

private async void Register()

Note though that RelayCommand won't await call to Register method but within Register method the execution will be serial.

Upvotes: 2

Related Questions