The ISplashScreenService allows a developer execute a batch of tasks en-queued and show the progress through a registered IPleaseWaitService or IUIVisualizerService type, from the main entry point of the application (typically from the bootstrapper) or a view model.
First of all is requiered resolve the instance of the registered ISplashScreenService type from the view model:
var dependencyResolver = this.GetDependencyResolver(); var splashScreenService = dependencyResolver.Resolve<ISplashScreenService>(); |
or from the application bootstrapper, after a previous service registration:
ServiceLocator.Default.RegisterTypeIfNotYetRegistered<ISplashScreenService, SplashScreenService>(); /*...*/ var splashScreenService = ServiceLocator.Default.ResolveType<ISplashScreenService>(); |
To en-queue tasks use the following code:
splashScreenService.Enqueue(new ActionTask("Creating the shell", OnCreateShell)); splashScreenService.Enqueue(new ActionTask("Initializing modules", OnInitializeModules)); splashScreenService.Enqueue(new ActionTask("Starting application", OnStartApplication)); |
To execute the batch of en-queued tasks, and show the progress through the IPleaseWaitService, use the following code:
splashScreenService.Commit(); |
To execute the batch of en-queued tasks, and show the progress through the IUIVisualizerService, use the following code:
splashScreenService.Commit<MySplashScreenViewModel>(); |
or:
splashScreenService.Commit(typeof(MySplashScreenViewModel)); |
To execute the batch of en-queued tasks asynchronously, and show the progress through the IPleaseWaitService, use the following code:
splashScreenService.CommitAsync(OnBatchCompleted); |
To execute the batch of en-queued task asynchronously, and show the progress through the IUIVisualizerService, use the following code:
splashScreenService.CommitAsync<MySplashScreenViewModel>(OnBatchCompleted); |
or:
splashScreenService.CommitAsync(OnBatchCompleted, typeof(MySplashScreenViewModel)); |
To notify the progress of an action task smoothly, use the argument of type ITaskProgressTracker just like is used in the following code:
private void OnInitializeModules(ITaskProgressTracker tracker) { int registeredModulesCount = 0; foreach (var module in ModuleCatalog.Modules) { tracker.UpdateStatus((int)(100.0f * (registeredModulesCount / ModuleCatalog.Modules.Count)), string.Format("Registering module '{0}'", module.ModuleName)); if (RegisterModule(module)) { registeredModulesCount++; } } } |
After committing the batch is cleared, so to execute it again you should en-queue the tasks again |
The SplashScreenService is thread-safe |