public IntegrationProcessor(int updateInterval, ProjectIntegrationService projectIntegrationService, Timer timer) { _updateInterval = updateInterval; _projectIntegrationService = projectIntegrationService; timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); timer.Interval = _updateInterval; //Don't wait for first elapsed time - Should not be used when running as a service due to that Starting will hang up until the queue is empty if (Environment.UserInteractive) { OnTimedEvent(null, null); } _workerIsRunning = false; }
protected override void OnStart(string[] args) { try { // Add code here to start your service. logger.Info($"Starting IntegrationService"); var updateIntervalString = ConfigurationManager.AppSettings["UpdateInterval"]; var updateInterval = 60000; Int32.TryParse(updateIntervalString, out updateInterval); var projectHost = ConfigurationManager.AppSettings["ProjectIntegrationServiceHost"]; var projectIntegrationApiService = new ProjectIntegrationApiService(new Uri(projectHost)); var projectDbContext = new ProjectDbContext(); var projectIntegrationService = new ProjectIntegrationService(projectIntegrationApiService, projectDbContext); timer = new System.Timers.Timer(); timer.AutoReset = true; var integrationProcessor = new IntegrationProcessor(updateInterval, projectIntegrationService, timer); timer.Start(); } catch (Exception e) { logger.Fatal(e); } }