private async void ChangeState(object parameter) { SocketConnection socket = new SocketConnection(address, 1234); bool success; // Will try to change the lock state, but only if the action is confirmed by the RPi if (LockState == LockState.OFF) { success = await socket.ChangeState(LockState.ON); if (success) { LockState = LockState.ON; LockSwitchAction = "Unlock Device"; } else { await App.Current.MainPage.DisplayAlert("Error", "Couldn't communicate with the device", "OK"); } } else if (LockState == LockState.ON) { success = await socket.ChangeState(LockState.OFF); if (success) { LockState = LockState.OFF; LockSwitchAction = "Lock Device"; } else { await App.Current.MainPage.DisplayAlert("Error", "Couldn't communicate with the device", "OK"); } } }