0

I am using C# to create a Silverlight 4 application.

I am trying to do the following:

        MapNode endNode = null;

        if (keyword != null && keyword != "")
        {
            EntityQuery<NodeIDProj> res = CampusQueries.getNodeIDByNameQuery(keyword);

            var queryres = CampusQueries.Load<NodeIDProj>(res, (items) =>
            {
                foreach (var item in items.Entities)
                {
                    MapNode n = mapHelp.getNodeByID(item.NodeID);

                    if (n != null)
                    {
                        endNode = n;
                        TrackAnimation();

                    }
                }

            }, true);
         }

However, after this point, my variable endNode is still null. TrackAnimation() works as though endNode has a valid value, but outside of the Load statement, endNode is back to null.

I know that I am lacking in understanding of how this works, and I would really appreciate an help given.

What I am trying to do, is query my database and I want to use those results in other methods rather than displaying them in a datagrid.

I want endNode to have value which I can use in other methods.

Please help me to figure out a way to do this, thank you!

EDIT:

Thank you, SLaks

Can I do something like:

MapNode endNode = null;

    if (keyword != null && keyword != "")
    {
        EntityQuery<NodeIDProj> res = CampusQueries.getNodeIDByNameQuery(keyword);

        var queryres = CampusQueries.Load<NodeIDProj>(res, (items) =>
        {
            foreach (var item in items.Entities)
            {
                MapNode n = mapHelp.getNodeByID(item.NodeID);

                if (n != null)
                {
                    endNode = n;
                    TrackAnimation();

                }
            }

        }, true);
     }
 queryres.Completed += new EventHandler(queryres_Completed);




void queryres_Completed(object sender, EventArgs e)
{
    //stuff
}

If so, how can I get access to the endNode variable, as it is declared within another method?

1 Answer 1

1

Your Load method is probably asynchronous, meaning that the callback happens some time after the rest of your code runs.

You can only use the result after you actually receive it.

Sign up to request clarification or add additional context in comments.

2 Comments

@Valerie: Only inside the callback, which will run after the method itself finishes.
thanks! I have another question to post, hope you are still around :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.