コード例 #1
0
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);
            log.Info("Service starting");
            try
            {
                subscribers    = new SubscriberGroup();
                scanner        = new MMMSwipeReader();
                scanStoreCloud = new ScanStoreCloud(_configFileName);
                serviceHost    = RemoteFactory.CreateServiceHost(this);
                BindScanSourceToScanStore(scanner, scanStoreCloud);

                serviceHost.Open();
                scanner.Activate();
                log.InfoFormat("Service started and listening at ", RemoteFactory.PipeLocation);
            }
            catch (Exception e)
            {
                log.ErrorFormat("Service exception while starting [{0}]", e);
                EventLog.WriteEntry(this.ServiceName, e.Message,
                                    System.Diagnostics.EventLogEntryType.Warning);
                EventLog.WriteEntry(this.ServiceName, e.StackTrace,
                                    System.Diagnostics.EventLogEntryType.Warning);
                OnStop();
                throw e;
            }
        }
コード例 #2
0
        protected override void OnStop()
        {
            log.Info("Service stopping");
            if (serviceHost != null)
            {
                serviceHost.Close();
                serviceHost = null;
            }

            cleanup(scanner);
            scanner = null;
            cleanup(scanStoreCloud);
            scanStoreCloud = null;
            cleanup(subscribers);
            subscribers = null;
            log.Info("Service stopped");
        }