mercredi 31 octobre 2018

Is there a way to know if other method is completed?

So I have a method

internal async Task UpdateMethod(string[] commands)
{
    while (expression) {
        //some code...
        SendCommandToSomewhere(command);
        //I want to pause here to continue upon receiving a response
    }
}

Then I register following method as event

charac.ValueChanged += Charac_ValueChanged;

Command then is being received by device (in unknown time), device sends a response which rises an EventHandler

private async void Charac_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
{
    //working with response
}

Basically I want to continue work in UpdateMethod() when I receive a response from the device. I suppose I can do something like boolean field, and then run Task.Delay(); in loop to check if this boolean == true, but I think that it is very wrong approach. How can I do that in the correct way?

Aucun commentaire:

Enregistrer un commentaire