コード例 #1
0
        public async Task TestSimpleAsyncQueueMerging()
        {
            var simpleQueue = new SimpleAsyncWorkerQueue <int>();

            var first = simpleQueue.QueueOrMergeAsync(1, async delegate
            {
                await Task.Delay(1000);

                return(1);
            });

            var second = simpleQueue.QueueOrMergeAsync(2, async delegate
            {
                await Task.Delay(1000);

                return(50);
            });

            var secondReplacement = simpleQueue.QueueOrMergeAsync(2, async delegate
            {
                await Task.Delay(1000);

                return(2);
            });

            await Task.Delay(1500);

            Assert.AreEqual(1, first.Result);
            Assert.IsFalse(second.IsCompleted);
            Assert.IsFalse(secondReplacement.IsCompleted);

            await Task.Delay(1000);

            Assert.AreEqual(2, second.Result);
            Assert.AreEqual(2, secondReplacement.Result);

            var secondButNew = simpleQueue.QueueOrMergeAsync(2, async delegate
            {
                await Task.Delay(1000);

                return(22);
            });

            var secondButAlreadyRunning = simpleQueue.QueueOrMergeAsync(2, async delegate
            {
                await Task.Delay(1000);

                return(222);
            });

            Assert.AreEqual(22, await secondButNew);

            await Task.Delay(500);

            Assert.IsFalse(secondButAlreadyRunning.IsCompleted);
            await Task.Delay(1000);

            Assert.AreEqual(222, secondButAlreadyRunning.Result);
        }
コード例 #2
0
        public static async System.Threading.Tasks.Task UpdatePrimaryTileNotificationsAsync()
        {
            try
            {
                await _updatePrimaryTileNotificationsWorkQueue.QueueOrMergeAsync(0, async delegate
                {
                    await System.Threading.Tasks.Task.Run(async delegate
                    {
                        var account = await AccountsManager.GetLastLogin();

                        AccountDataStore data = null;

                        if (account != null)
                        {
                            data = await AccountDataStore.Get(account.LocalAccountId);
                        }

                        await UpdatePrimaryTileNotificationsBlocking(account, data);
                    });
                });
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
                Debug.WriteLine("Failed UpdatePrimaryTileNotificationsAsync");
            }
        }
コード例 #3
0
        public Task ResetAllRemindersAsync(AccountDataItem account)
        {
            // If they weren't enabled, we won't do anything. The only time they get disabled is from settings, and we'll clear when that happens.
            if (!account.AreClassRemindersEnabled())
            {
                return(Task.CompletedTask);
            }

            return(_workQueue.QueueOrMergeAsync(account.LocalAccountId, () => Task.Run(async delegate
            {
                try
                {
                    ScheduleViewItemsGroup scheduleViewItemsGroup = null;

                    var currSemesterId = account.CurrentSemesterId;
                    if (currSemesterId != Guid.Empty && account.AreClassRemindersEnabled())
                    {
                        // We don't need to worry about holding a lock though, if the collections change and that breaks us, that's fine,
                        // that implies that the data has been changed anyways and another ResetReminders will come in.
                        // Therefore we should also expect to get some exceptions here.
                        scheduleViewItemsGroup = await ScheduleViewItemsGroup.LoadAsync(account.LocalAccountId, currSemesterId, trackChanges: false, includeWeightCategories: false);
                    }

                    ResetAllReminders(account, scheduleViewItemsGroup);
                }
                catch (Exception ex)
                {
                    TelemetryExtension.Current?.TrackException(ex);
                }
            })));
        }
コード例 #4
0
 public static Task <ImageAttachmentLoadResult> DownloadImageAsync(IFolder imagesFolder, string imageName, string imageUrl)
 {
     return(_downloadsQueue.QueueOrMergeAsync(imageUrl, delegate
     {
         return DownloadImageHelperAsync(imagesFolder, imageName, imageUrl);
     }, allowMergeWithAlreadyStarted: true));
 }