[英]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.