嵌套的EventHandler回调:什么时候完成?

时间:2013-09-12 14:19:50

标签: c# event-handling

我尝试将AsanaNet集成到我的项目中(https://github.com/acron0/AsanaNet),并且遇到嵌套的EventHandler回调的一般问题。

数据查询没有问题。我只是不知道所有EventHandler /任务何时完成,因为有几个带有异步回调的foreach循环。虽然从workspace2查询了所有用户,但用户表单workspace1尚未完成。

我何时知道何时加载了所有工作区的所有用户?

上述AsanaNet的例子:

asanaConn.GetWorkspaces(asanaWorkspaces =>
{
    foreach (AsanaWorkspace asanaWorkspace in asanaWorkspaces)
    {
        asanaConn.GetUsersInWorkspace(asanaWorkspace, asanaUsers =>
        {
            foreach (AsanaUser asanaUser in asanaUsers)
            {
                Console.WriteLine("asanaUser: " + asanaUser.Name);
            }
        });
    }
});

回调:

public void GetTasksInWorkspace(AsanaWorkspace arg1,  AsanaUser arg2, AsanaCollectionResponseEventHandler callback)
{
    var request = GetBaseRequest(AsanaFunction.GetFunction(Function.GetTasksInWorkspace), arg1, arg2);
    request.Go((o, h) => PackAndSendResponseCollection<AsanaTask>(o, callback), ErrorCallback);
}

1 个答案:

答案 0 :(得分:0)

要么我总是忽略它,要么现在异步方法可以与Wait()同步;

所以我的问题解决了。

https://github.com/acron0/AsanaNet#asananet

asana.GetMe(o =>
{
    var user = o as AsanaUser;
    Console.WriteLine("Hello, " + user.Name);
}).Wait();   <---------------