Barney Chambers
Barney Chambers

Reputation: 2783

Xamarin Forms C# Async function implementation

If I run this code, will editButton wait to become enabled until my (asynchronous) getMachines() function has finished running? If not, how do I create this functionality?

 editButton.isEnabled = false;
 loadedMachines = await azureService.GetMachines();
 editButton.isEnabled = true;

Upvotes: 1

Views: 51

Answers (2)

Michel Amorosa
Michel Amorosa

Reputation: 495

Yes, await keyword will make your thread wait for the response.

Don't forget to add async keywork on your method and to return a Task<> in GetMachines()

Upvotes: 1

Zain Ahmad Khan
Zain Ahmad Khan

Reputation: 497

Yes edit button will wait for upper functionality to finish first.

Upvotes: 2

Related Questions