protected sealed override void OnStart(System.String[] args) { var section = Configuration.FileCopyMonitorSection.GetSection(); if (null == section) { return; } var monitors = section.Monitors.OfType <Configuration.MonitorElement>(); if ((null == monitors) || !monitors.Any()) { return; } System.String name; System.String entry; foreach (var m in monitors) { try { myProcess.Add(new Process(m, myLog)); } catch (System.Exception e) { myLog(System.String.Format("Exception: {0}\r\n{1}\r\nStack Trace follows:\r\n{2}", e.GetType().Name, e.Message, e.StackTrace)); this.Stop(); throw; } #if TRACE name = m.Name; foreach (var path in m.Paths.OfType <Configuration.PathElement>()) { foreach (var filter in path.Filters.OfType <Configuration.FilterElement>()) { entry = System.String.Format("Monitoring {0} : {1}\\{2}", name, path.Path, filter.Filter); myLog(entry); } } #endif } System.Threading.Tasks.Parallel.ForEach(myProcess.AsParallel(), x => x.Start()); #if TRACE entry = "All monitors activated"; myLog(entry); #endif }