예제 #1
0
        /// <summary>
        /// starts service and creates the main objects of the exercise
        /// </summary>
        /// <param name="args"> for starting service. </param>
        protected override void OnStart(string[] args)
        {
            // In order to create the ImageServiceModal we need to read two fields from the App.config
            string outputFolder  = ConfigurationManager.AppSettings["OutputDir"];
            int    thumbnailSize = Int32.Parse(ConfigurationManager.AppSettings["ThumbnailSize"]);

            logger = new LoggingService();
            modal  = new ImageServiceModal(outputFolder, 120);

            controller    = new ImageController(modal);
            m_imageServer = new ImageServer(logger, controller);
            m_imageServer.createHandlers();
            ServiceStatus serviceStatus = new ServiceStatus();

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint     = 100000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            eventLog1.WriteEntry("In OnStart");
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 60000; // 60 seconds
            timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);
            timer.Start();
            timer.Enabled = true;

            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
        }