private void StartThread([NotNull] ProcessActionInfo pai) { try { Thread t = new Thread(ProcessSingleAction) { Name = "ProcessSingleAction(" + pai.TheAction.Name + ":" + pai.TheAction.ProgressText + ")" }; if (actionWorkers is null) { Logger.Error( $"Asked to start for {pai.TheAction.Name}, but actionWorkers has been removed, please restart TV Rename and contact help if this recurrs."); return; } actionWorkers.Add(t); actionStarting = true; // set to false in thread after it has the semaphore t.Start(pai); } finally { int nfr = pai.Sem.Release(); // release our hold on the semaphore, so that worker can grab it ThreadsLogger.Trace("ActionProcessor[" + pai.Sem + "] pool has " + nfr + " free"); } }
/// <summary> /// Processes an Action by running it. /// </summary> /// <param name="infoIn">A ProcessActionInfo to be processed. It will contain the Action to be processed</param> public void ProcessSingleAction(Object infoIn) { try { ProcessActionInfo info = infoIn as ProcessActionInfo; if (info == null) { return; } this.ActionSemaphores[info.SemaphoreNumber].WaitOne(); // don't start until we're allowed to this.ActionStarting = false; // let our creator know we're started ok Action action = info.TheAction; if (action != null) { logger.Trace("Triggering Action: {0} - {1} - {2}", action.Name, action.Produces, action.ToString()); action.Go(ref this.ActionPause, mStats); } this.ActionSemaphores[info.SemaphoreNumber].Release(1); } catch (Exception e) { logger.Fatal(e, "Unhandled Exception in Process Single Action"); return; } }