/// <summary>
        /// Constructs the BackgroundTaskManager (and the progress monitor task)
        /// </summary>
        public BackgroundTaskManager(ViewManager viewManager)
        {
            if (Instance != null)
            {
                throw new InvalidOperationException("This class must only be instantiated once.");
            }
            Instance   = this;
            Tasks      = new Dictionary <string, BackgroundTask>();
            _uiContext = SynchronizationContext.Current;
            if (_uiContext == null)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
            _uiThreadId          = Thread.CurrentThread.ManagedThreadId;
            _delayedPostActions  = new Queue <Func <bool> >();
            _viewManager         = viewManager;
            _discardableTaskKeys = new List <string>();
            _taskFactory         = new System.Threading.Tasks.TaskFactory(TaskScheduler.Default);

            // Create the progress monitor task
            _progressMonitor = new Task(ProgressMonitorTask);
            _progressMonitor.Start();
        }
Exemple #2
0
 /// <summary>
 /// Creates an BackgroundTask
 /// </summary>
 /// <param name="source">The manager</param>
 /// <param name="loadingProgressViewModel">The progress indicator view model</param>
 /// <param name="key">The key for the task (only one parallel task per key may run simultaneously)</param>
 /// <param name="ctx">The callers' synchronization context</param>
 internal BackgroundTask(BackgroundTaskManager source, LoadingProgressViewModel loadingProgressViewModel, string key, SynchronizationContext ctx)
 {
     Ctx = ctx;
     LoadingProgressViewModels = new List <LoadingProgressViewModel>();
     LoadingProgressViewModels.Add(loadingProgressViewModel);
     Cancelled      = new CancellationTokenSource();
     _trackProgress = new TrackProgressImpl();
 }