public BgTasksManagerService(IBgTaskFactory bgTaskFactory)
 {
     this.BgTaskFactory = bgTaskFactory;
     this.AdminstrateTasksCancellationToken = new CancellationTokenSource();
     this.AdminstrateTasksTask = PeriodicalRepetitiveTask.Create((now, ct) => this.AdminstrateTasks(ct), this.AdminstrateTasksCancellationToken.Token, TimeSpan.FromSeconds(1));
     this.AdminstrateTasksTask.Post(DateTimeOffset.Now);
 }
        public override void ActivateDbSetChangeNotifier(Type dbSetType)
        {
            var autoRefreshArgs = this.AutoRefreshArgsDictionary.GetOrAdd(dbSetType, type => new AutoRefreshArgs(dbSetType));

            var lastEntityCount = this.Set(dbSetType).Local.Count;
            var prt             = PeriodicalRepetitiveTask.Create((now, ct) => Task.Run(() =>
            {
                var currentEntityCount = this.Set(dbSetType).Local.Count;
                if (lastEntityCount == currentEntityCount)
                {
                    return;
                }
                lastEntityCount = currentEntityCount;
                this.OnDbSetChanged(new DbSetChangedArgs(dbSetType));
            }, ct), autoRefreshArgs.CancellationTokenSource.Token, TimeSpan.FromSeconds(5));

            prt.Post(DateTimeOffset.Now);
        }