Refactoring, upgrades and improvements to memory usage
This commit is contained in:
parent
a076f6b8fb
commit
cfbc6334b6
4 changed files with 212 additions and 234 deletions
|
|
@ -49,7 +49,7 @@ namespace MaddoShared
|
|||
stopwatch.Stop();
|
||||
|
||||
return
|
||||
$"{stopwatch.Elapsed.Hours}h {stopwatch.Elapsed.Minutes}m ${stopwatch.Elapsed.Seconds}s ({stopwatch.Elapsed.TotalSeconds}s)";
|
||||
$"{stopwatch.Elapsed.Hours}h {stopwatch.Elapsed.Minutes}m {stopwatch.Elapsed.Seconds}s ({stopwatch.Elapsed.TotalSeconds}s)";
|
||||
}
|
||||
|
||||
public async Task ProcessImagesParallel(
|
||||
|
|
@ -64,16 +64,17 @@ namespace MaddoShared
|
|||
int threads = options.MaxThreads;
|
||||
|
||||
Bitmap logoBmp = null;
|
||||
// Load Logo
|
||||
if (picSettings.LogoAggiungi & File.Exists(picSettings.LogoNomeFile))
|
||||
// Load Logo (short-circuit)
|
||||
if (picSettings.LogoAggiungi && File.Exists(picSettings.LogoNomeFile))
|
||||
{
|
||||
logoBmp = new Bitmap(picSettings.LogoNomeFile);
|
||||
}
|
||||
|
||||
Func<FileData, Task> processFile = async fileData =>
|
||||
{
|
||||
using var logoCopy = logoBmp.Clone(new Rectangle(0, 0, logoBmp.Width, logoBmp.Height),
|
||||
logoBmp.PixelFormat);
|
||||
Bitmap logoCopy = logoBmp is null
|
||||
? null
|
||||
: logoBmp.Clone(new Rectangle(0, 0, logoBmp.Width, logoBmp.Height), logoBmp.PixelFormat);
|
||||
|
||||
var imgState = new ImageState
|
||||
{
|
||||
|
|
@ -81,26 +82,28 @@ namespace MaddoShared
|
|||
DestDir = fileData.Directory,
|
||||
};
|
||||
|
||||
await imageCreatorService.CreaImmagineThread(imgState, logoCopy);
|
||||
|
||||
// using var imgCreator = new ImageCreatorSharp(fileData.File, fileData.Directory, picSettings);
|
||||
// await imgCreator.CreaImmagineThread(fileData.File.Name, logoCopy);
|
||||
|
||||
results.Add(fileData.File.Name);
|
||||
|
||||
try
|
||||
{
|
||||
updateEvent?.Invoke(this, new Tuple<string, int>(fileData.File.Name, dataToProcess.Count));
|
||||
// Ensure CreateImageAsync can accept a null logoCopy value.
|
||||
await imageCreatorService.CreateImageAsync(imgState, logoCopy);
|
||||
|
||||
results.Add(fileData.File.Name);
|
||||
|
||||
try
|
||||
{
|
||||
updateEvent?.Invoke(this, new Tuple<string, int>(fileData.File.Name, dataToProcess.Count));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Error in reporting update");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
finally
|
||||
{
|
||||
logger.LogError(e, "Error in reporting update");
|
||||
throw;
|
||||
// Dispose the clone if it was created
|
||||
logoCopy?.Dispose();
|
||||
}
|
||||
// finally
|
||||
// {
|
||||
// imgCreator = null;
|
||||
// }
|
||||
};
|
||||
|
||||
if (options.LinearExecution)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<OutputType>Library</OutputType>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue