Hi,
I've used async calls before now in a couple of different projects and
wanted to see if the new async stuff in the 4.7 branch will make things
simpler.
My old code looks like this
(in OnCreate)
Button login = FindViewById<Button> (Resource.Id.buttonSignIn);
login.Click += SignIn_Click;
MyEvents.UserSignIn_Completed += UserSignIn_Completed;
private void SignIn_Click(object src, EventArgs e)
{
MyEvents.UserSignIn_Async (userId, userPwd);
}
private void UserSignIn_Completed (object sender, MyStuff_EventArgs_Bool e)
{
string result = String.Format ("Sign-in {0} successful", e.Result ?
"was" : "was NOT");
try
{
if ( e.Success )
{
StartActivity(typeof(nextActivity);
}
else
{
result = String.Format ("Something went wrong [{0}]",
e.ErrorMessage);
Console.WriteLine("Error message=" + e.ErrorMessage);
}
}
catch(Exception err)
{
Console.WriteLine("UserExists_Completed Exception:" +
err.Message);
}
}
If I've read MSDN correctly, I should be able to transform that into
something much simpler...
(in OnCreate)
login.Click += delegate
{
loginUser(username.Text, password.Text, mobile.Text);
};
private async void loginUser(string username, string password, string
mobile)
{
Task<MyStuff_EventArgs_Bool> getLoginTask =
MyEvents.UserSignIn_Async(username, password);
MyStuff_EventArgs_Bool e = await getLoginTask;
if (e.Success)
{
StartActivity(typeof(FrontPage));
} else
{
RunOnUiThread(() => GeneralUtils.Alert(context,
Resource.String.errLoginTitle, e.ErrorMessage));
return;
}
}
The problem though is the UserSignIn_Async returns void and you can't
have Task<void>. Changing the return type of the method to Task causes a
problem at the caller line.
Can anyone point out what I've misinterpreted please as I'm pretty sure
the new async code in Xam.Android will be much quicker than the old way
and I'd rather be using that.
Paul
--
"Space," it says, "is big. Really big. You just won't believe how
vastly, hugely, mindbogglingly big it is. I mean, you may think it's a
long way down the road to the chemist's, but that's just peanuts to
space, listen..."
Hitch Hikers Guide to the Galaxy, a truly remarkable book!
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid