I am creating a small project using MvvMCross in a PCL Xamarin project and having a problem with the async Task that I invoke in the button-related command.
I have a fake web service where I just call Task.Delay (3000). When the process comes to this point, it just sits and does nothing.
I initially had a command call using the .wait () call, but read somewhere that it was a blocking call and could not be sliced ββasync / wait
Can someone help and give me a hint about where I am going wrong by linking a team?
https://bitbucket.org/johncogan/exevaxamarinapp is a public git repo, specific command
public ICommand SaveProfile
in the ProfileViewModel.cs file.
Specific code:
public ICommand SaveProfile
{
get
{
return new MvxCommand(() =>
{
if (_profile.IsValidData())
{
EnumWebServiceResult taskResult;
Mvx.Resolve<IProfileWebService>().SendProfileToServer(_profile).Wait();
if(_profileWebService.getLastResponseResult() == true){
taskResult = EnumWebServiceResult.SUCCESS;
}else{
taskResult = EnumWebServiceResult.FAILED_UNKNOWN;
}
}
});
}
}
Web Service Class ():
using System;
using System.Threading.Tasks;
using ExevaXamarinApp.Models;
namespace ExevaXamarinApp.Services
{
public class FakeProfileWebService : IProfileWebService
{
public int _delayPeriod { get; private set; }
public bool? lastResult;
public FakeProfileWebService()
{
_delayPeriod = 3000;
lastResult = null;
}
private Task Sleep()
{
return Task.Delay(3000);
}
public bool? getLastResponseResult(){
return lastResult;
}
public async Task SendProfileToServer(Profile profileObject)
{
if (profileObject.IsValidData())
{
await Sleep();
lastResult = true;
}else{
lastResult = false;
}
}
}
}