private bool TryStartApplication(Func <bool> startApplication, bool startManagePrintJobs) { var success = false; try { _logger.Debug("Starting pipe server"); success = _pipeServerManager.StartServer(); if (!success) { return(false); } _logger.Debug("Reloading settings"); // Settings may have changed as this may have not been the only instance till now _settingsManager.LoadAllSettings(); if (startManagePrintJobs) { _jobInfoQueueManager.ManagePrintJobs(); } _logger.Debug("Finding spooled jobs"); var spooledJobs = _spooledJobFinder.GetJobs(); _jobInfoQueue.Add(spooledJobs); success = startApplication(); } catch (Exception ex) { _logger.Error(ex, "There was an error while starting the application"); success = false; throw; } finally { if (!success) { _pipeServerManager.Shutdown(); } } return(success); }