diff --git a/VECTO/GUI/MainForm.vb b/VECTO/GUI/MainForm.vb index b560e734f54aefceae56a062712bdc44b9672b90..97a83102913813ce33a974cd8c99a29975983961 100644 --- a/VECTO/GUI/MainForm.vb +++ b/VECTO/GUI/MainForm.vb @@ -1080,7 +1080,7 @@ Imports TUGraz.VectoCore.Utils Return End If - Dim progress As Dictionary(Of Integer, JobContainer.ProgressEntry) = jobContainer.GetProgress() + Dim progress As IDictionary(Of Integer, JobContainer.ProgressEntry) = jobContainer.GetProgress() Dim sumProgress As Double = progress.Sum(Function(pair) pair.Value.Progress) Dim duration As Double = (DateTime.Now() - start).TotalSeconds diff --git a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs index aea993981827f262a1531e89300889cb1fefacbe..293cde435008d6ca76e45fabcbfa0ef1ba5f3512 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs @@ -356,20 +356,19 @@ namespace VECTO3GUI2020.ViewModel.Implementation } SimulationRunning = true; try { - //await Task.Run(() => RunSimulationAsync(_cancellationTokenSource.Token, - // outputMessages: _outputMessage, - // progress: _progress, - // status: _status, - // jobToSimulate: jobToSimulate)); - await Task.Factory.StartNew(() => RunSimulationAsync(_cancellationTokenSource.Token, - outputMessages: _outputMessage, - progress: _progress, - status: _status, - jobToSimulate: jobToSimulate), - TaskCreationOptions.LongRunning | - TaskCreationOptions.PreferFairness).Unwrap(); + await Task.Run(() => RunSimulationAsync(_cancellationTokenSource.Token, + outputMessages: _outputMessage, + progress: _progress, + status: _status, + jobToSimulate: jobToSimulate)); + //await Task.Factory.StartNew(() => RunSimulationAsync(_cancellationTokenSource.Token, + // outputMessages: _outputMessage, + // progress: _progress, + // status: _status, + // jobToSimulate: jobToSimulate), + // TaskCreationOptions.LongRunning).Unwrap(); - } + } catch (Exception ex) { _outputViewModel.AddMessage(new MessageEntry() { Type = MessageType.ErrorMessage, @@ -632,7 +631,8 @@ namespace VECTO3GUI2020.ViewModel.Implementation PrintRuns(justFinished, fileWriters, outputMessages); finishedRuns.AddRange(justFinished.Select(x => x.Key)); - Task.Delay(200, ct).Wait(200); //Used to reduce updates of UI Thread, under heavy load it's possible that Task.Delay() is not scheduled and we hang here, therefore the Timeout. + var delayMs = 500; + Task.Delay(delayMs, ct).Wait(delayMs); } start.Stop(); diff --git a/VectoConsole/Program.cs b/VectoConsole/Program.cs index e14008517b96205a4d3f4737d9c7cc8fe6877051..0df22028197a780a4d8dfafa519711cafb79cd18 100644 --- a/VectoConsole/Program.cs +++ b/VectoConsole/Program.cs @@ -359,7 +359,7 @@ Examples: WriteLine($@"VectoCore: {VectoSimulationCore.VersionNumber}"); } - private static void PrintProgress(Dictionary<int, JobContainer.ProgressEntry> progessData, + private static void PrintProgress(IDictionary<int, JobContainer.ProgressEntry> progessData, bool showTiming = true, bool force = false) { try { diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/JobContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/JobContainer.cs index d5ec68ba0a375e42451d265f1f5d3610aa9710c6..dc9b50121b11db19c49861c2c8a7dce85be7d1b0 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/JobContainer.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/JobContainer.cs @@ -126,7 +126,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl private bool _canceled = false; private ReaderWriterLockSlim _cancelLock = new ReaderWriterLockSlim(); - + private ConcurrentDictionary<int, ProgressEntry> _progressDictionary = + new ConcurrentDictionary<int, ProgressEntry>(); + /// <summary> /// Initializes a new empty instance of the <see cref="JobContainer"/> class. @@ -315,7 +317,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl Task.WaitAll(tasks); } - [MethodImpl(MethodImplOptions.Synchronized)] + //[MethodImpl(MethodImplOptions.Synchronized)] private void JobCompleted(int runId, int runContainerId) { try { @@ -375,26 +377,56 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } } - public Dictionary<int, ProgressEntry> GetProgress() + public IDictionary<int, ProgressEntry> GetProgress() { try { _runsRwLock.EnterReadLock(); - return Runs.ToDictionary( - r => r.Run.RunIdentifier, - r => new ProgressEntry + foreach (var runEntry in Runs) { + var key = runEntry.Run.RunIdentifier; + //Update existing entry + if(_progressDictionary.ContainsKey(key)) { - RunId = r.Run.RunIdentifier, - JobRunId = r.Run.JobRunIdentifier, - RunName = r.Run.RunName, - CycleName = r.Run.CycleName, - RunSuffix = r.Run.RunSuffix, - Progress = r.Run.Progress, - Done = r.Done, - ExecTime = r.ExecTime, - Success = r.Success, - Canceled = r.Canceled, - Error = r.ExecException - }); + var entry = _progressDictionary[key]; + entry.Progress = runEntry.Run.Progress; + entry.Done = runEntry.Done; + entry.ExecTime = runEntry.ExecTime; + entry.Success = runEntry.Success; + entry.Canceled = runEntry.Canceled; + entry.Error = runEntry.ExecException; + } else { + var progressEntry = new ProgressEntry { + RunId = runEntry.Run.RunIdentifier, + JobRunId = runEntry.Run.JobRunIdentifier, + RunName = runEntry.Run.RunName, + CycleName = runEntry.Run.CycleName, + RunSuffix = runEntry.Run.RunSuffix, + Progress = runEntry.Run.Progress, + Done = runEntry.Done, + ExecTime = runEntry.ExecTime, + Success = runEntry.Success, + Canceled = runEntry.Canceled, + Error = runEntry.ExecException + }; + _progressDictionary[key] = progressEntry; + } + } + return _progressDictionary; + //return Runs.ToDictionary( + // r => r.Run.RunIdentifier, + // r => new ProgressEntry + // { + // RunId = r.Run.RunIdentifier, + // JobRunId = r.Run.JobRunIdentifier, + // RunName = r.Run.RunName, + // CycleName = r.Run.CycleName, + // RunSuffix = r.Run.RunSuffix, + // Progress = r.Run.Progress, + // Done = r.Done, + // ExecTime = r.ExecTime, + // Success = r.Success, + // Canceled = r.Canceled, + // Error = r.ExecException + // }); } finally { _runsRwLock.ExitReadLock(); }