public void PerformFetch(UIApplication application, Action <UIBackgroundFetchResult> completionHandler)
        {
            try
            {
                var tdelay = Task.Delay(21 * 1000);
                backgroundStatus = UIBackgroundFetchResult.NewData;
                if (currentBackupTask == null)
                {
                    currentBackupTask = Task.Run(BackgroundBackupImages);
                }

                var res = Task.WhenAny(new[] { tdelay, currentBackupTask }).Result;
                if (res == currentBackupTask)
                {
                    currentBackupTask = null;
                    completionHandler?.Invoke(backgroundStatus);
                    return;
                }
                completionHandler?.Invoke(UIBackgroundFetchResult.NewData);
            }
            catch (Exception e)
            {
                logger.LogError(e, "PerformFetch");
                try
                {
                    completionHandler?.Invoke(UIBackgroundFetchResult.Failed);
                }
                catch
                {
                }
            }
        }
        async Task BackgroundBackupImages()
        {
            logger.LogTrace("Background App Refresh triggered.");

            var cloud = Globals.CloudManager.PersonalClouds?[0];

            if (cloud == null)
            {
                logger.LogError("Backup triggered while no Personal Cloud configured.");
                backgroundStatus = UIBackgroundFetchResult.Failed;
                return;
            }

            var worker = Globals.BackupWorker;

            if (worker == null)
            {
                logger.LogError("Photo sync worker not initialized.");
                backgroundStatus = UIBackgroundFetchResult.NoData;
                return;
            }


            var path = Globals.Database.LoadSetting(UserSettings.PhotoBackupPrefix);

            if (string.IsNullOrEmpty(path))
            {
                logger.LogError("Photo sync not configured.");
                backgroundStatus = UIBackgroundFetchResult.Failed;
                return;
            }

            try
            {
                WaitForPath(cloud, path);
            }
            catch (Exception exception)
            {
                logger.LogError(exception, "Exception occurred while wait for node appearing when backup photos.");
                backgroundStatus = UIBackgroundFetchResult.NoData;
                return;
            }

            try
            {
                var items = await worker.StartBackup(cloud.RootFS, path, true).ConfigureAwait(false);

                backgroundStatus = UIBackgroundFetchResult.NoData;
            }
            catch
            {
                backgroundStatus = UIBackgroundFetchResult.Failed;
            }
        }