At a guess, it's to do with timing.

You could be returning your list f from your function before the Async
network call has occurred.

To get around this, change your method from:

   private List<string> DoThis()

to:

   private void DoThisAndCallMeBack(Action<List<string>> callback)

And then modify the return statements to callback calls:

List<string> f = new List<string>();
           if (checkForNetwork(true) != true)
           {
               f.Add("No network available");
                callback(f);
               return;
           }

               List<Upcoming> tableData = new List<Upcoming>();
               POHWS.webservice.Service1 Service3 = new
POHWS.webservice.Service1();

               try
               {
                   Service3.BeginGetUpcoming(**track, delegate(IAsyncResult
iar)
                   {
                       tableData = Service3.EndGetUpcoming(iar).**ToList();
                       Android.App.Application.**
SynchronizationContext.Post(**delegate
                       {
                           if (tableData.Count == 0)
                           {
                               tableData[0].PostTime = "No data from the
webservice";
                           }

                           f.Add(tableData[0].PostTime);
                           Console.WriteLine("f[0] = {0}", f[0]);
                           callback (f);
                       }, null);
                   }, null);
               }
               catch (Exception oe)
               {
                   f.Add(oe.ToString());
                   callback(f);
               }

You might also need to marshall the callback calls on to the UI thread

Hope that works and helps

Stuart

On 2 March 2012 02:29, Paul Johnson <[email protected]> wrote:

> Hi,
>
> This is probably down to me being a klutz, but can anyone spot why nothing
> is being returned? The Console.WriteLine is showing that something is being
> added to the list. I'm guessing a scope problem...
>
> (calling routine)
> case 1:
>                            List<string> race = new List<string>();
>                            currentview.**SetBackgroundDrawable(**
> Resources.GetDrawable(**Resource.Drawable.Back_**BobMoore));
>                            text.Text = Resources.GetString(Resource.**
> String.ComingSoon);
>                            webservice_user getRace = new webservice_user();
>                            race = getRace.getUpcomingRaces("**
> fairmeadowsUpcoming");
>                            races = race.ToArray();
>                            break;
>
> (webservice)
> List<string> f = new List<string>();
>            if (checkForNetwork(true) != true)
>            {
>                f.Add("No network available");
>                return f;
>            }
>            else
>            {
>                List<Upcoming> tableData = new List<Upcoming>();
>                POHWS.webservice.Service1 Service3 = new
> POHWS.webservice.Service1();
>
>                try
>                {
>                    Service3.BeginGetUpcoming(**track,
> delegate(IAsyncResult iar)
>                    {
>                        tableData = Service3.EndGetUpcoming(iar).**
> ToList();
>                        Android.App.Application.**
> SynchronizationContext.Post(**delegate
>                        {
>                            if (tableData.Count == 0)
>                            {
>                                tableData[0].PostTime = "No data from the
> webservice";
>                            }
>
>                            f.Add(tableData[0].PostTime);
>                            Console.WriteLine("f[0] = {0}", f[0]);
>                        }, null);
>                    }, null);
>                }
>                catch (Exception oe)
>                {
>                    f.Add(oe.ToString());
>                    return f;
>                }
>            return f;
>            }
>
> Not sure, it could also be the 
> Android.App.Application.**SynchronizationContext.Post
> code.
>
> Any help here would be appreciated. Thanks
>
> Paul
> ______________________________**_________________
> Monodroid mailing list
> [email protected]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/**mailman/listinfo/monodroid<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