private BackgroundTaskManager()
 {
     using (var context = new TaskSchedulerDbContext())
     {
         foreach (Job job in context.Jobs)
         {
             AddJob(job);
         }
     }
 }
        private async void RunJobsAtTime(List <Job> jobs, int milisecondsDelay)
        {
            await Task.Delay(milisecondsDelay);

            foreach (Job job in jobs)
            {
                Debug.WriteLine("RUN JOB: " + job.Name);
                Cron.CronStructure cs = cronMapping[job];
                ScheduleJob(job, cs);

                using (var context = new TaskSchedulerDbContext())
                {
                    UriAction[]          uriActions          = context.UriActionsForActionPredicate(x => x.JobId == job.Id);
                    NotificationAction[] notificationActions = context.NotificationActionsForActionPredicate(x => x.JobId == job.Id);
                    ApplicationAction[]  applicationActions  = context.ApplicationActionsForActionPredicate(x => x.JobId == job.Id);
                    try
                    {
                        foreach (var action in uriActions)
                        {
                            await Launcher.LaunchUriAsync(new Uri(action.Uri));
                        }

                        foreach (var action in notificationActions)
                        {
                            Toast.ShowToastNotification(job.Name, action.Text, action.Image, action.Audio, action.Timeout);
                        }

                        await appListProvider.IsDoneTask.ContinueWith(async (Task) =>
                        {
                            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, async() =>
                            {
                                foreach (var action in applicationActions)
                                {
                                    var appQuery = appListProvider.AppList.Where(x => x.Package.Id.FullName == action.ApplicationName);
                                    if (appQuery.Any())
                                    {
                                        AppEntry entry = appQuery.First();
                                        bool opr       = await entry.Entry.LaunchAsync();
                                        while (!opr)
                                        {
                                            await Task.Delay(1000);
                                            opr = await entry.Entry.LaunchAsync();
                                        }
                                    }
                                }
                            });
                        });
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.Message);
                    }
                }
            }
        }