Hi all,
In our sample application we need to call the Async/Await function when the property is changed.
For Example, when we type a character in Xamarin.Forms.Labs.Autocomplete control, we need to call WCF REST Service to fetch data against the typed character.
Note: The below is working fine with Android&iOS but fails to wait for Async/Await call for Property in Windows Phone.
Please find the sample code and suggest .
public string _getsearchtext { get; private set; }
public string SearchText
{
set
{
if (_getsearchtext != value)
{
_getsearchtext = value;
this.OnPropertyChanged("SearchText");
if (_getsearchtext + "" != "")
LoadSite();
}
}
get { return _getsearchtext; }
}
public async Task LoadSite()
{
try
{
object[] Parameters = new object[2];
Parameters[0] =UserCode;
Parameters[1] = _getsearchtext;
if (_dataaccess == null)
_dataaccess = new DataAccess();
List_site = await _dataaccess.GetUsersite(Parameters); // When this line executed Android&iOS waits for result and process data, but windows phone executes next line without waiting for Asyn/await.
itemsList = new ObservableCollection<HelpDesk>(List_site);
Items = new ObservableCollection<Object>();
for (var i = 0; i < itemsList.Count; i++)
{
Items.Add(new TestPerson(string.Format(itemsList[i].Description + ""), string.Format(itemsList[i].HD_Equipment + ""), Convert.ToInt16(itemsList[i].HD_Code + "")));
}
}
catch (Exception ex)
Debug.WriteLine(ex.Message.ToString());
}