acron0 / AsanaNet

.NET API for Asana (www.asana.com)
MIT License
38 stars 29 forks source link

How to know that data is loaded complete. #6

Closed thangtx closed 11 years ago

thangtx commented 11 years ago

Hi everyone

Could you tell me when data loading from Asana is completed and can bind into a data grid?

Thanks and regards,

acron0 commented 11 years ago

Each individual AsanaNet call comes with a delegate callback which is called when the relevant data as returned. You can see an example of this in the README example.

thangtx commented 11 years ago

Hi Antony Readme example not include, could you please update Readme with this example. Thank you.

robertmiles3 commented 11 years ago

@thangtx, yes, it is already included in the README. For instance, this example in the README:

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

The o => {...} is the delegate section where you add your code for what you would like to do with the data returned. In this example, once GetMe returns with data, we simply assign a variable for the AsanaUser that is returned, then write the name to the console.

thangtx commented 11 years ago

Hi Robert

Let see my test:

using System; using AsanaNet; namespace AsanaConsoleApplication { public class Program { private const string _apiKey = "API"; private static Action<string, string, string> _errorCallback; private static Asana _asana; private static void Main(string[] args) { Console.WriteLine("Step 1"); _asana = new Asana(_apiKey, AuthenticationType.Basic, _errorCallback); var user = new AsanaUser(); _asana.GetMe(o => { user = o as AsanaUser; }); Console.WriteLine("Step 2"); _asana.GetWorkspaces(o => { foreach (AsanaWorkspace workspace in o) { Console.WriteLine("Workspace Name={0}", workspace.Name); } }); Console.WriteLine("Step 3"); _asana.GetWorkspaces(o => { foreach (AsanaWorkspace workspace in o) { _asana.GetProjectsInWorkspace(workspace, projects => { foreach (AsanaProject project in projects) { Console.WriteLine("Project Name=" + project.Name); } } ); } }); Console.WriteLine("Step 4"); Console.ReadKey(); } } }

And output is

image

My expected output is:

Step 1 Step 2 Workspace Name=RDICC Workspace Name=Personal Project Step 3 Project Name="Cong viec thang 6" Project Name="Chua co deadline"

So I want to know how I can wait for all data is loaded i.e: Workspace loaded before console writing "Step 3".

Thanks and regards,

acron0 commented 11 years ago

AsanaNet is an asynchronous framework which means that each call (_asana.GetMe, _asana.GetWorkspace etc) is non-blocking. You invoke the method and the application will return a result at some undetermined point in the future. If you want to wait until a particular call has returned then you need to rethink the design of your application and potentially use a Thread.Sleep solution.

thangtx commented 11 years ago

Hi Antony Thanks for your reply. Do you have a other solution instead of Thread.Sleep because I still don't known how long to sleep.

Best regards,

acron0 commented 11 years ago
while(!dataReturned) {
    Thread.Sleep(1);
}

We have helped you as much as we can. Your problems are not related to AsanaNet and demonstrate a fundamental lack of programming methodology knowledge and experience. I suggest you brush up on the basics.

thangtx commented 11 years ago

Hi Antony I know this is not issue but I can't find forum for this project so I post here. Thanks for you help.