diff --git a/IOB-MAN.Core/Services/AppControlService.cs b/IOB-MAN.Core/Services/AppControlService.cs index f88a284..50021d4 100644 --- a/IOB-MAN.Core/Services/AppControlService.cs +++ b/IOB-MAN.Core/Services/AppControlService.cs @@ -214,39 +214,73 @@ namespace IOB_MAN.Core.Services { isBusy = true; CheckRunningChild(); - // provo a chiudere tutti 1:1 per pID - var listPID = ListIobAdapters - .Where(x => x.isRunning) - .Select(x => x.pID) - .ToList(); -#if true - Parallel.ForEach(listPID, pID => + if (ListIobAdapters.Count > 0) + { + List listPID = new List(); + try { - ForceKillByPID(pID); - }); -#else - foreach(var pID in listPID) - { - ForceKillByPID(pID); - } -#endif + // provo a chiudere tutti 1:1 per pID + listPID = ListIobAdapters + .Where(x => x.isRunning) + .Select(x => x.pID) + .ToList(); - // chiudo per nome SE rimasti - var listNames = currIobConf - .ListTarget - .Select(x => x.Value.ExeName) - .Where(x => !string.IsNullOrEmpty(x)) - .Distinct().ToList(); - Parallel.ForEach(listNames, prgName => - { - ForceKillByName(prgName); - }); - // aspetto 100ms + } + catch (Exception exc) + { + Log.Error($"Eccezione DoCloseAll.01:{Environment.NewLine}{exc}"); + } + if (listPID.Count > 0) + { + Parallel.ForEach(listPID, pID => + { + ForceKillByPID(pID); + }); + // aspetto 100ms + Task.Delay(100); + } + +#if false + List listNames = new List(); + try + { + // chiudo per nome SE rimasti + listNames = currIobConf + .ListTarget + .Select(x => x.Value.ExeName) + .Where(x => !string.IsNullOrEmpty(x)) + .Distinct().ToList(); + } + catch (Exception exc) + { + Log.Error($"Eccezione DoCloseAll.02:{Environment.NewLine}{exc}"); + } +#endif + List listNames = ListIobNames(); + if (listNames.Count > 0) + { + Parallel.ForEach(listNames, prgName => + { + ForceKillByName(prgName); + }); + } + } // verifico nuovamente i processi CheckRunningChild(); - var stillRunList = ListIobAdapters - .Where(x => x.isRunning) - .ToList(); + List stillRunList = new List(); + if (ListIobAdapters.Count > 0) + { + try + { + stillRunList = ListIobAdapters + .Where(x => x.isRunning) + .ToList(); + } + catch (Exception exc) + { + Log.Error($"Eccezione DoCloseAll.03:{Environment.NewLine}{exc}"); + } + } // eventuale chiusura if (stillRunList != null && stillRunList.Count > 0) { @@ -256,7 +290,6 @@ namespace IOB_MAN.Core.Services ForceKillByName(item.ExeName); } } - // verifico se resettare if (doReset) { @@ -270,6 +303,34 @@ namespace IOB_MAN.Core.Services isBusy = false; } + /// + /// Elenco degli EXE Names degli IOB gestiti (x chiamate di cleanup/chiusura) + /// + /// + private List ListIobNames() + { + List listNames = new List(); + if (currIobConf != null && currIobConf.ListTarget != null && currIobConf.ListTarget.Count > 0) + { + // chiudo per nome SE rimasti + listNames = currIobConf + .ListTarget + .Select(x => x.Value.ExeName) + .Where(x => !string.IsNullOrEmpty(x)) + .Distinct().ToList(); +#if false + try + { + } + catch (Exception exc) + { + Log.Error($"Eccezione DoCloseAll.02:{Environment.NewLine}{exc}"); + } +#endif + } + return listNames; + } + /// /// Apre il child selezionato /// @@ -729,7 +790,7 @@ namespace IOB_MAN.Core.Services #region Private Methods - private bool checkIstance(IobAdapt item, List processList) + private bool checkInstance(IobAdapt item, List processList) { bool needRem = false; if (!isBusy) @@ -830,11 +891,14 @@ namespace IOB_MAN.Core.Services ); // ciclo controllo var list2check = concList.ToList(); - Parallel.ForEach(ListIobAdapters, item => + if (list2check != null && list2check.Count > 0) { - needRem = checkIstance(item, list2check); + Parallel.ForEach(ListIobAdapters, item => + { + needRem = checkInstance(item, list2check); + } + ); } - ); } } sw.Stop(); @@ -893,11 +957,14 @@ namespace IOB_MAN.Core.Services ); // ciclo controllo var list2check = concList.ToList(); - Parallel.ForEach(ListIobAdapters, item => + if (list2check != null && list2check.Count > 0) { - needRem = checkIstance(item, list2check); + Parallel.ForEach(ListIobAdapters, item => + { + needRem = checkInstance(item, list2check); + } + ); } - ); } } sw.Stop(); @@ -1089,7 +1156,6 @@ namespace IOB_MAN.Core.Services if (startProc) { - // chiudo eventuali processi in RUN DoCloseAll(false); diff --git a/IOB-MAN/IOB-MAN.csproj b/IOB-MAN/IOB-MAN.csproj index 40f40c9..6a11bf6 100644 --- a/IOB-MAN/IOB-MAN.csproj +++ b/IOB-MAN/IOB-MAN.csproj @@ -8,7 +8,7 @@ enable true enable - 4.0.2512.0608 + 4.0.2512.1208 Debug;Release;Remote_DEBUG false