Exemplo n.º 1
0
        /// <summary>
        /// Start engine host.
        /// This will start each task in registered in this host.
        /// </summary>
        /// <param name="token">
        /// A CancellationToken to observe while waiting for the tasks to complete.
        /// </param>
        /// <param name="timeout">
        /// The number of milliseconds to wait, or Infinite (-1) to wait indefinitely
        /// </param>
        public Task Start(CancellationToken token, Int32 timeout)
        {
            return(Task.Factory.StartNew(() =>
            {
                var watch = Stopwatch.StartNew();

                // Try to start all tasks
                var tasks = _tasks
                            .Select(p => Task.Factory.StartNew(() => p.Run(token)))
                            .ToArray();

                // Engine started
                SystemInformer.Notify(new EngineStarted(_taskNames));

                try
                {
                    // Wait for all tasks to be either completed or canceled
                    Task.WaitAll(tasks, timeout, token);
                }
                catch (OperationCanceledException)
                {
                    // Do nothing
                }

                // Engine stopped
                SystemInformer.Notify(new EngineStopped(watch.Elapsed));
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize Engine TaskEngine
        /// </summary>
        internal void Initialize()
        {
            // About to initialize
            SystemInformer.Notify(new EngineInitializing());

            // Initialize all tasks
            foreach (var process in _tasks)
            {
                process.Init();
            }

            // All process initialized
            SystemInformer.Notify(new EngineInitialized());
        }