Пример #1
0
 private async Task PushItem(BackgroundUpdateScheduleHandler item)
 {
     using (var releaser = await _ScheduleUpdateLock.LockAsync())
     {
         // 重複登録を防止しつつ、追加処理
         if (UpdateTargetStack.All(x => x != item))
         {
             UpdateTargetStack.Add(item);
             UpdateTargetStack.Sort((a, b) => b.Priority - a.Priority);
         }
     }
 }
Пример #2
0
        public BackgroundUpdateScheduleHandler InstantBackgroundUpdateScheduling(
            IBackgroundUpdateable target,
            string id,
            string groupId = null,
            int priority   = 0,
            string label   = null
            )
        {
            var handler = new BackgroundUpdateScheduleHandler(target, this, id, groupId, priority, label);

            handler.ScheduleUpdate();
            return(handler);
        }
Пример #3
0
        private async void StartTaskAndRegistration(BackgroundUpdateScheduleHandler item)
        {
            var cancelTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var taskInfo          = new RunningTaskInfo()
            {
                Target                  = item.Target,
                Item                    = item,
                CancelTokenSource       = cancelTokenSource,
                CurrentUpdateTargetTask =
                    Task.Run(async() =>
                {
                    try
                    {
                        await item.Target.BackgroundUpdate(UIDispatcher)
                        .AsTask(cancelTokenSource.Token);
#if DEBUG
                        await Task.Delay(500);
#endif
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }

                    return(item);
                }
                             )
                    .ContinueWith(OnContinueTask)
            };


            // キャンセル時の処理
            taskInfo.CancelTokenSource.Token.Register(OnTaskCanceled, taskInfo);

            Debug.WriteLine($"BGTask[{Id}]: begining update {taskInfo.Item.Id}");

            (item as BackgroundUpdateScheduleHandler)?.Start(UIDispatcher);

            BackgroundUpdateStartedEvent?.Invoke(this, item);

            using (var releaser = await _ScheduleUpdateLock.LockAsync())
            {
                _RunningTasks.Add(taskInfo);
            }
        }
Пример #4
0
        public BackgroundUpdateScheduleHandler RegistrationBackgroundUpdateScheduleHandler(
            IBackgroundUpdateable target,
            string id,
            string groupId = null,
            int priority   = 0,
            string label   = null
            )
        {
            // Note: ここで予めBGUpdateInfo同士の
            // 依存関係解決の元になる情報を構築することもできる
            BackgroundUpdateScheduleHandler handler;

            if (_UpdateInfoMap.ContainsKey(target))
            {
                handler = _UpdateInfoMap[target];
            }
            else
            {
                handler = new BackgroundUpdateScheduleHandler(target, this, id, groupId, priority, label);
                _UpdateInfoMap.Add(target, handler);
            }

            return(handler);
        }
Пример #5
0
        /// <summary>
        /// スケジュール
        /// BackgroundUpdateInfo から呼ばれます
        /// </summary>
        /// <param name="item"></param>
        internal async void Schedule(BackgroundUpdateScheduleHandler item)
        {
            await PushItem(item);

            await TryBeginNext();
        }