private void ChangePassword(Hardware hw, string newPassword) { Log($"Updating password for {hw.Address}..."); try { var task = hw.ChangePasswordHardware(newPassword); var i = 0; while (task.State == StateEnum.InProgress & i++ < 100) { Task.Delay(100).Wait(); task.UpdateState(); } } catch (Exception ex) { Log($"An error occurred while updating password for {hw.Address}. {ex.Message}"); } }