简体   繁体   English

如何将异步方法作为动作传递?

[英]How to pass an async method as an action?

I've this method: 我有这个方法:

public class Publish
{
    public async Task NowAsync(bool isFinal)
    {
        //...
    }
}

and I want to pass it as a parameter here instead of () => Console.WriteLine() : 我想把它作为参数传递给这里而不是() => Console.WriteLine()

RecurringJob.AddOrUpdate("name", () => Console.WriteLine("Hello"));

AddOrUpdate method accepts a parameter of type Expression<Action> AddOrUpdate方法接受Expression<Action>类型的参数

How can I do it? 我该怎么做? thanks. 谢谢。

hangfire 1.6 (此时为1。5年)开始,您可以将异步方法(返回Task方法)传递给AddOrUpdate而无需将它们转换为同步方法(对于Action ):

RecurringJob.AddOrUpdate("name", () => NowAsync(true), (string) null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM