如何在 C# 中定义异步操作?
How can I Define an Async Action in c#?
我很想知道有没有办法定义动作变量async
?或者其他替代方法?
public System.Action myAction;
public async System.Action myAsyncAction;
void Start()
{
// normal action
myAction += () =>
{
Debug.Log("Inject some code in runtime..");
};
// I want something like this that support wait time..
myAsyncAction += () =>
{
await Task.Delay(2000f);
Debug.Log("Inject some code in runtime..");
};
}
我以前用过 Func<Task>
。例如:
Func<Task> asyncMethod = async () =>
{
await Task.Delay(1000);
Console.WriteLine("done here");
};
await asyncMethod();
我很想知道有没有办法定义动作变量async
?或者其他替代方法?
public System.Action myAction;
public async System.Action myAsyncAction;
void Start()
{
// normal action
myAction += () =>
{
Debug.Log("Inject some code in runtime..");
};
// I want something like this that support wait time..
myAsyncAction += () =>
{
await Task.Delay(2000f);
Debug.Log("Inject some code in runtime..");
};
}
我以前用过 Func<Task>
。例如:
Func<Task> asyncMethod = async () =>
{
await Task.Delay(1000);
Console.WriteLine("done here");
};
await asyncMethod();