Passing in an Action<string> is an asynchronous programming trick - I think
this is "functional programming" (and someone will hopefully correct me if
I'm wrong.

Basically you would declare your method like:
       private void
getUpcomingRaces(Action<List<string>> callback) { ... }

Then you would call it with:

private void SomeMethod()
{
getUpcomingRaces((list) => {
Console.WriteLine("list received of size " + list.Count);
foreach (var line in list)
{
    Console.WriteLine(line);
}
});
}

Or you could pass in a method group instead of an anonymous method if you
prefer - e.g.:

private void SomeMethod()
{
getUpcomingRaces(ListProcessor);
}

private void ListProcessor(List<string> list)
{
Console.WriteLine("list received of size " + list.Count);
foreach (var line in list)
{
    Console.WriteLine(line);
}
}





On 2 March 2012 13:43, nodoid <[email protected]> wrote:

> Hi,
>
> That's getting me a good bit further, but there is still something not
> quite
> right. The new code looks like this
>
>        private string rTrack;
>
>        public List<string>getUpcomingRaces(string track)
>         {
>            List<string>f = new List<string>();
>             rTrack = track;
>            f = getUpcomingRacesCallBack(cb);
>            return f;
>        }
>
>        private List<string>
> getUpcomingRacesCallBack(Action<List&lt;string>> callback)
>         {
>            List<string> f = new List<string>();
>            if (checkForNetwork(true) != true)
>            {
>                f.Add("No network available");
>                callback(f);
>            }
>             else
>            {
>                List<POHWS.webservice.UpcomingRaces> tableData = new
> List<POHWS.webservice.UpcomingRaces>();
>                 POHWS.webservice.Service1 Service3 = new
> POHWS.webservice.Service1();
>
>                try
>                {
>                     Service3.BeginGetUpcomingRacesList(rTrack,
> delegate(IAsyncResult iar)
>                    {
>                        tableData =
> Service3.EndGetUpcomingRacesList(iar).ToList();
>
> Android.App.Application.SynchronizationContext.Post(delegate
>                        {
>                            if (tableData.Count == 0)
>                            {
>                                 tableData[0].PostTime = "No Upcoming Races
> Found within the next 7 days";
>                            }
>                            else
>                            {
>                                for (int i = 0; i < tableData.Count; ++i)
>                                    f.Add(tableData[i].PostTime);
>                            }
>                            callback(f);
>                            //return f;
>                        }, null);
>                        callback(f);
>                     }, null);
>                }
>                catch (Exception oe)
>                {
>                    f.Add(oe.ToString());
>                    callback(f);
>                     //return f;
>                }
>            }
>            return f;
>        }
>
> I have tried this code and it returns nothing (much as before). Now, if I
> change the 2nd method to a void, how can I then propogate List<string> to
> return it to the caller?
>
> Thanks
>
> Paul
>
> --
> View this message in context:
> http://mono-for-android.1047100.n5.nabble.com/Nothing-being-passed-back-from-a-webservice-tp5529892p5531003.html
> Sent from the Mono for Android mailing list archive at Nabble.com.
> _______________________________________________
> Monodroid mailing list
> [email protected]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
>
_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to