private void UpdateCloudStatus(CloudStatus newStatus)
 {
     if (CloudStatus == newStatus)
     {
         return;
     }
     CloudStatus = newStatus;
     OnCloudStatusUpdated?.Invoke(this, System.EventArgs.Empty);
 }
        private async void WaitForTheCloudAsync()
        {
            while (true)
            {
                WaitingForTheCloud = true;
                OnCloudStatusUpdated?.Invoke(null, EventArgs.Empty);
                if (_cloudWaitsCount > MaxCloudWaitsCount)
                {
                    _cloudWaitsCount          = 0;
                    _waitingForTheCloudToLoad = false;
                    _waitingForTheCloudToSave = false;
                    UpdateCloudStatus(CloudStatus.CloudDisconnected);
                }
                else
                {
                    await Task.Delay(TimeSpan.FromSeconds(MinTimeBetweenCloudSaves));

                    _cloudWaitsCount++;
                }

                if (CloudStatus == CloudStatus.CloudUpdating)
                {
                    continue;
                }

                if (_waitingForTheCloudToLoad)
                {
                    _waitingForTheCloudToLoad = false;
                    LoadData();

                    if (_waitingForTheCloudToSave)
                    {
                        _cloudWaitsCount = 0;
                        continue;
                    }
                }

                if (_waitingForTheCloudToSave)
                {
                    _waitingForTheCloudToSave = false;
                    SaveData();
                }

                _cloudWaitsCount   = 0;
                WaitingForTheCloud = false;
                OnCloudStatusUpdated?.Invoke(null, EventArgs.Empty);
                break;
            }
        }