我如何从按钮调用异步方法 [英] How do i call async method from a button

查看:33
本文介绍了我如何从按钮调用异步方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用故事板设计器在 alpha 中使用最新的 xamrian 调用 aysnc 方法,但我似乎无法从设计人员声明的按钮单击中调用该方法.客服

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();        
}

但是如果我们看下面的designer.cs文件

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);

推荐答案

根据您的问题,我假设您不能像这样将 async 修饰符添加到事件处理程序中?

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();        
}

我通常使用 lambda 进行内联点击:

I generally do my clicks inline using a lambda:

btnSave.TouchUpInside += async (sender, e) => 
{
    await Createuser(); 
};

这篇关于我如何从按钮调用异步方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆