在C#/ XAML中的Windows 8应用程序中,我有时想从非异步方法调用awaitable方法。是否可以在非异步方法中调用awaitable方法?
其实是正确的,以取代本:
public async Task<string> MyCallingMethod()
{
string result = await myMethodAsync();
return result;
}
本:
public string MyCallingMethod()
{
Task.Run(async() => {
string result = await myMethodAsync();
return result;
});
}
优点对我来说,我可以用MyCallingMethod无需等待,但是这是正确的? 如果我想传递MyCallingMethod的ref参数,这可能是一个优点,因为在async方法中不可能有ref参数。
不会工作。您的匿名异步函数不会将值返回给外部函数。 – Denis