public void CancelAll()
		{
			State = ServiceHostState.Stopping;

			this.WriteInfoMessage(string.Format("Cancelling {0} hosted services.", Services.Count));

			foreach (var tokenSource in _taskTokenSources.Values)
			{
				tokenSource.Cancel();
			}

			try
			{
				Task.WaitAll(_taskMap.Values.ToArray(), _shutdownTimeout);
			}
			catch (AggregateException e)
			{
				foreach (var innerException in e.InnerExceptions)
				{
					_serviceExceptions.Add(innerException);
				}
			}

			State = ServiceHostState.Stopped;
		}
		public void Cancel(Guid id)
		{
			checkForHostedService(id);

			this.WriteInfoMessage(string.Format("Cancelling hosted service {0}, identifier {1}.", Services[id].Name, id));

			State = ServiceHostState.Stopping;

			_taskTokenSources[id].Cancel();

			_taskMap[id].Wait();

			State = ServiceHostState.Stopped;
		}
		public void StartAll()
		{
			State = ServiceHostState.Starting;

			this.WriteDebugMessage(string.Format("Starting service host with {0} hosted services.", Services.Count));

			foreach (var task in _taskMap.Select(taskMapEntry => taskMapEntry.Value))
			{
				if (task.Status == TaskStatus.WaitingToRun || task.Status == TaskStatus.Created)
				{
					task.Start();
				}
			}

			State = ServiceHostState.Started;

			this.WriteInfoMessage(string.Format("Started service host with {0} hosted services.", Services.Count));
		}
		public void Start(Guid id)
		{
			checkForHostedService(id);

			State = ServiceHostState.Starting;

			_taskMap[id].Start();

			State = ServiceHostState.Started;

			this.WriteInfoMessage(string.Format("Started hosted service {0}, identifier {1}.", Services[id].Name, id));
		}