Wait for async Task for first method in xamarin froms
Prashant Sharma
66
Reputation points
I am using async and await in my project and my first method is running in second method for ex- when data will save then print command will run print is depend on save and print command must run after save , but in my code sometime print command do not wait for save command execute ,that why I am getting deadlock error and Violation of PRIMARY KEY constraint in database. I am sharing my code. Thank u for help
public async void ExecutePrintCommand()
{
UserDialogs.Instance.ShowLoading("Saving", MaskType.Clear);
await Task.Delay(1000);
try
{
var SaveStatus = await Save();
if SaveStatus == 1)
{
UserDialogs.Instance.ShowLoading("Printing");
await Task.Delay(1000);
await Print();
await App.Current.MainPage.Navigation.PushAsync(new RootPage());
}
else
{
Device.BeginInvokeOnMainThread(() =>
{
navigation.PopAsync();
});
}
}
Developer technologies | .NET | Xamarin
5,378 questions
Developer technologies | C#
11,584 questions
Sign in to answer