【发布时间】:2014-01-02 06:52:34
【问题描述】:
[实际上,我不确定问题是否与anonymous和delgate有关。]
在我的应用程序中,我使用异步创建新项目。在 AddNew 方法中,它将调用从 repo 类中创建一个新项目,然后将其添加到列表项目中。 create 方法有参数,但有返回值。
问题是我真的不知道如何用匿名调用创建方法。
代码如下。
protected void AddNew()
{
_repo.Create(() => AddToListItem(x)) // I want the value (x) that return from repository.Create to use with AddToListItem(x)
}
public P Create(Action completed = null)
{
var p = new P();
Insert(p);
return p;
}
public void Insert(P p, Action completed = null)
{
_service.Insert(p,
() =>
{
if (onCompleted != null)
{
onCompleted();
}
}
);
}
【问题讨论】:
-
以上代码不是异步的。此外,尚不清楚您要做什么。请详细说明。
标签: c# asynchronous callback delegates anonymous