我试图在下面找到一个优雅的 Execute(..) 方法实现,它接受一个 lambda 表达式。我想要做的甚至可能吗?似乎我应该能够,因为编译器将允许我传递这样的 lambda 表达式(以 Action 的形式)。
static void Main(string[] args)
{
// This should execute SomeOperation() synchronously
Execute(() => SomeOperation());
// This should begin execution of SomeOperationAsync(), but not wait (fire and forget)
Execute(() => SomeOperationAsync());
// This should await the execution of SomeOperationAsync() (execute synchronously)
Execute(async () => await SomeOperationAsync());
}
给定这些规范,您将如何实现上面的 Execute 方法?