Hi,
This could possibly be down to my current state of needing sleep but then
again, it could be something else. I've searched for examples on how to fix
the problem below, but can't seem to find what I need and it's starting to
drive me potty!
Essentially, I have a race condition whereby the webservice is finishing way
after return has been given to the UI, so the UI is not displaying anything
at all.
Here's the code. The webservice does actually get the correct data which is
the pain of it all! The generateNewScreen method comes as a result of
clicking some text on a ListView area
(calling routine)
private void generateNewScreen(int t)
{
string[] races = new string[] { };
View currentview =
FindViewById<View>(Resource.Id.relLayout);
TextView text =
FindViewById<TextView>(Resource.Id.textTitle);
ListView listView =
FindViewById<ListView>(Resource.Id.listView);
ImageView image =
FindViewById<ImageView>(Resource.Id.imgBack);
image.Visibility = ViewStates.Visible;
Console.WriteLine("t = {0}, addFactor = {1}", t,
addFactor);
switch (addFactor)
{
case 0:
switch (t)
{
case 0: races =
listviewInfo(Resource.Array.RaceTracks,
Resource.Drawable.Back_RaceHorsePlace, Resource.String.Tracks);
addFactor = 10;
break;
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("RP");
races =
race.ToArray();
addFactor = 20;
break;
}
if (t < 6 || t == 7)
listView.Adapter = new
ArrayAdapter<string>(this, Resource.Layout.listview_layout, races);
break;
}
(webservice)
private string rTrack;
public List<string> getUpcomingRaces(string track)
{
List<string> f = new List<string>();
rTrack = track;
getUpcomingRacesCallBack((list) =>
{
f = list;
});
return f;
}
private void getUpcomingRacesCallBack(Action<List<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)
{
f.Add("No Upcoming Races Found within
the next 7 days");
callback(f);
}
else
{
for (int i = 0; i < tableData.Count;
++i)
f.Add(tableData[i].PostTime);
callback(f);
}
}, null);
}, null);
}
catch (Exception oe)
{
f.Add(oe.ToString());
callback(f);
}
}
}
Is it possible to either stop the UI or delay updating until the webservice
has done what it needs? I've tried quite a lot of things, including using a
ProgressDialog - for some reason, it dies though with a Java error (guessing
I can't just use the "this" bit - the docs say it should work...)
(code I'm using is this)
ProgressDialog d = new ProgressDialog(this); <- dies here
d.SetMessage("Please wait");
d.SetTitle("Loading");
d.Show();
Any help or advice or titbits of info would be appreciated on this.
Thanks
Paul
--
View this message in context:
http://mono-for-android.1047100.n5.nabble.com/UI-threading-problem-tp5532804p5532804.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