等待来自setter属性的异步函数 [英] Await an async function from setter property

查看:145
本文介绍了等待来自setter属性的异步函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要等待来自属性设置器方法的异步功能.

I need to await to an async function from a property setter method.

public String testFunc()
{
get
{

}
set
{
    //Await Call to the async func <asyncFunc()>

}
}

我知道我们不应该创建异步属性,那么实现此目的的最佳方法是什么.

I understand we should not make async properties, so what is the optimal way to do this.

推荐答案

您不能创建异步属性,并且不应该想要-属性暗示 fast ,非阻塞操作.如果您需要执行长时间运行的活动(如要执行异步操作并等待它所暗示的那样),则根本不要使其成为属性.

You can't make async properties and you shouldn't want to - properties imply fast, non blocking operations. If you need to perform a long running activity, as implied by you're wanting to kick of an async operation and wait for it, don't make it a property at all.

删除设置器,然后改用方法.

Remove the setter and make a method instead.

这篇关于等待来自setter属性的异步函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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