C# .NET 4, How to pass the task completion result to another method?

Viewed 105

I am integrating Google Firebase in Unity Game Engine using C#.

Here's my code:

FirebaseApp.DefaultInstance.SetEditorDatabaseUrl(databaseUrl);
var firebaseDatabase = FirebaseDatabase.DefaultInstance;

firebaseDatabase.GetReference("SomePath").GetValueAsync().ContinueWith(task =>{
    HandleCallback(task.Result.ToDictionary());
});

void HandleCallback(dictionary<string,object> dic)
{
    Debug.Log(dic.Keys.Count);
}

I need to somehow pass the result to another method to handle completion. I can't seem to get this to work.

here's no error, the log is just empty.

However if I call the Debug.Log(dic.Keys.Count) inside the Task it works.

Hope to learn and make this work. Thank you.

1 Answers

Ok, this is strange, but I noticed if I manually create a dictionary from the result instead of using "ToDictionary()" the callback method is fired.

Hope it saves you time if you are having the same issue.

Related