【发布时间】:2018-05-07 18:01:21
【问题描述】:
我正在 Visual Studio 2017 中处理 Xamarin Forms 项目。我需要在线程中实现异步方法。
启动线程的事件
public void btnAction_Click(object sender, System.EventArgs e)
{
var load = new System.Threading.Thread((t) =>
{
ShowWarning();
});
load.Start(btnText);
}
异步方法应该在线程内部实现
private async void ShowWarning()
{
bool response = await DisplayAlert("Warning", "Please Enter
The Key","Yes","No");
}
【问题讨论】:
-
async void
仅用于事件处理程序。为什么要使用线程? -
为什么需要这样做? “在线程中实现任务in”是什么意思?
-
在该方法中还有另一部分功能(此处未提及),这就是为什么我将其放在线程中
标签: c# xamarin xamarin.forms