当仅传递 IList 时存储 IList 的任务



>我有以下属性:

public Func<EntityKey, string, Task<IList<MyProperty>>> RequestHandler { get; private set; }

我的类上还有一个构造函数,如下所示:

public RequestHandlerTasks(Func<EntityKey, string, IList<MyProperty>> handler)

如何操作传递到构造函数中的"处理程序",以便将其存储在"请求处理程序"属性中?

如果您没有发现它,构造函数使用"IList",并且属性需要 IList 的任务。

目前还不清楚语义的含义是什么,但它可以像以下一样简单:

public RequestHandlerTasks(Func<EntityKey, string, IList<MyProperty>> handler)
{
    // Whenever the RequestHandler delegate is called, it will start a new task.
    RequestHandler = (arg1, arg2) =>
        Task.Factory.StartNew(() => handler(arg1, arg2));
}

这将编译 - 它是否做你想要的是另一回事......

最新更新