/// <summary>
        /// Called when the service is stopped.
        /// </summary>
        protected override void OnStop()
        {
            try
            {
                // This shuts down the broker simulation when it is running.
                if (MarketSimulator.SimulatorParameters.IsExchangeSimulatorRunning)
                {
                    BrokerSimulator.Stop();
                }

                // This shuts down the price simulation when it is running.
                if (MarketSimulator.SimulatorParameters.IsPriceSimulatorRunning)
                {
                    PriceSimulator.Stop();
                }

                // Shut down each of the Web Services hosted by this Windows Service.
                foreach (ServiceHost serviceHost in this.serviceHosts)
                {
                    serviceHost.Close();
                }
            }
            catch (Exception exception)
            {
                // Any problems initializing should be sent to the Event Log.
                EventLog.WriteEntry(MarketSimulator.Source, String.Format("{0}: {1}", exception.Message, exception.StackTrace), EventLogEntryType.Information);
            }

            // Log the end of the service.
            try
            {
                EventLog.WriteEntry(
                    MarketSimulator.Source,
                    String.Format(Simulator.Properties.Resources.ServiceStopping, MarketSimulator.ServiceName),
                    EventLogEntryType.Information);
            }
            catch (SecurityException)
            {
            }
        }