private void OnExecutePluginProcess(object sender, PluginExecuteEventArgs e) { var handler = ExecutePluginProcess; if (null != handler) { handler(sender, e); } }
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { IMeasurer im = null; im = this.timers[(System.Timers.Timer)sender]; PluginExecuteEventArgs pe = new PluginExecuteEventArgs(im, e.SignalTime); this.OnExecutePluginProcess(sender, pe); }
void MeasurerService_ExecutePluginProcess(object sender, PluginExecuteEventArgs e) { IMeasurer im = e.MeasurerPlugin; if (im != null) { #if DEBUG log.Append(string.Format("Starting new Plugin {0} Process() task.", im.Name), EventLogEntryType.Information, true); #endif // see: http://stackoverflow.com/questions/17298269/catching-exceptions-caused-in-different-threads var task = Task.Factory.StartNew(im.Process); task.ContinueWith(t => PluginProcess_UnhandledException(t.Exception, im.Name), TaskContinuationOptions.OnlyOnFaulted); #if DEBUG log.Append(string.Format("Task run {0}.", im.Name), EventLogEntryType.Information, true); #endif } else { log.Append(string.Format("Measurer plugin class is null, cannot perform Measurer process. Service will be stopped."), EventLogEntryType.Error, 100, true); this.ExitCode = 100; this.Stop(); } }