Enhance image processing performance and flexibility by introducing atomic counters, improving file pattern matching, and refining logo positioning logic.
This commit is contained in:
parent
ba965e8266
commit
68c1106f65
8 changed files with 134 additions and 68 deletions
|
|
@ -846,6 +846,8 @@ namespace ImageCatalog_2
|
|||
private ConcurrentBag<string> _results = new();
|
||||
private int _currentAmount = 0;
|
||||
private int _previousAmount = 0;
|
||||
// Atomic counter for processed images — avoids expensive ConcurrentBag.Count enumerations
|
||||
private int _processedAtomic = 0;
|
||||
private System.Threading.Timer? _speedTimer;
|
||||
|
||||
private void Test(object parameter)
|
||||
|
|
@ -875,7 +877,7 @@ namespace ImageCatalog_2
|
|||
ProcessingStatus = "Elaborazione in corso...";
|
||||
TotalImagesCount = 0;
|
||||
ProcessedImagesCount = 0;
|
||||
SpeedCounter = "-f/m";
|
||||
SpeedCounter = "-f/s";
|
||||
ProgressBarValue = 0;
|
||||
ProgressBarMaximum = 100;
|
||||
|
||||
|
|
@ -902,9 +904,10 @@ namespace ImageCatalog_2
|
|||
_results = new ConcurrentBag<string>();
|
||||
_currentAmount = 0;
|
||||
_previousAmount = 0;
|
||||
_processedAtomic = 0;
|
||||
|
||||
// Start speed timer (every minute)
|
||||
_speedTimer = new System.Threading.Timer(UpdateSpeedCounter, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
|
||||
// Start speed timer (sample every second using lightweight atomic reads)
|
||||
_speedTimer = new System.Threading.Timer(UpdateSpeedCounter, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
|
||||
|
||||
var time = await _imageCreationService.CreaCatalogoParallel(
|
||||
imageCreationOptions,
|
||||
|
|
@ -940,17 +943,21 @@ namespace ImageCatalog_2
|
|||
private void UpdateSpeedCounter(object? state)
|
||||
{
|
||||
_previousAmount = _currentAmount;
|
||||
_currentAmount = _results.Count;
|
||||
// Read the atomic counter without enumerating the ConcurrentBag
|
||||
_currentAmount = System.Threading.Volatile.Read(ref _processedAtomic);
|
||||
int diff = _currentAmount - _previousAmount;
|
||||
SpeedCounter = $"{diff} f/m";
|
||||
// Report files per second (timer runs every 1s)
|
||||
SpeedCounter = $"{diff} f/s";
|
||||
}
|
||||
|
||||
private void OnImageProcessed(object? sender, Tuple<string, int> args)
|
||||
{
|
||||
ProcessedImagesCount = _results.Count;
|
||||
// Increment atomic processed counter once and use its value for all UI updates
|
||||
var processed = System.Threading.Interlocked.Increment(ref _processedAtomic);
|
||||
ProcessedImagesCount = processed;
|
||||
TotalImagesCount = args.Item2;
|
||||
ProgressBarMaximum = args.Item2;
|
||||
ProgressBarValue = _results.Count;
|
||||
ProgressBarValue = processed;
|
||||
ProcessingStatus = args.Item1;
|
||||
}
|
||||
|
||||
|
|
@ -1044,4 +1051,6 @@ namespace ImageCatalog_2
|
|||
await _settingsService.LoadSettingsAsync(filePath, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue