Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i call async method from a button

I am trying to call a aysnc method using latest xamrian in alpha using story board designer but i cant seem to call the method from a button click that has been declared by the desginer. CS

async public  void Createuser ()
{        
    var user = new ParseUser ()
    {
        Username = txtUserName.Text,
        Password = txtPassword.Text,
        Email = txtEmail.Text
    };

    await user.SignUpAsync ();
}

the button which i wish to call the method from is this

partial void btnSave_TouchUpInside (UIButton sender)
{
    Createuser();        
}

But if we look at the following i the designer.cs file

[Action ("btnSave_TouchUpInside:")]
[GeneratedCode ("iOS Designer", "1.0")]
partial void btnSave_TouchUpInside (UIButton sender);
like image 397
c-sharp-and-swiftui-devni Avatar asked Mar 20 '23 15:03

c-sharp-and-swiftui-devni


1 Answers

Based on your question, I assume that you can't just add the async modifier to the event handler as such?

async partial void btnSave_TouchUpInside (UIButton sender)
{
    await Createuser();        
}

I generally do my clicks inline using a lambda:

btnSave.TouchUpInside += async (sender, e) => 
{
    await Createuser(); 
};
like image 175
valdetero Avatar answered Mar 28 '23 08:03

valdetero