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();
|
stopwatch.Stop();
|
||||||
|
|
||||||
return
|
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(
|
public async Task ProcessImagesParallel(
|
||||||
|
|
@ -64,16 +64,17 @@ namespace MaddoShared
|
||||||
int threads = options.MaxThreads;
|
int threads = options.MaxThreads;
|
||||||
|
|
||||||
Bitmap logoBmp = null;
|
Bitmap logoBmp = null;
|
||||||
// Load Logo
|
// Load Logo (short-circuit)
|
||||||
if (picSettings.LogoAggiungi & File.Exists(picSettings.LogoNomeFile))
|
if (picSettings.LogoAggiungi && File.Exists(picSettings.LogoNomeFile))
|
||||||
{
|
{
|
||||||
logoBmp = new Bitmap(picSettings.LogoNomeFile);
|
logoBmp = new Bitmap(picSettings.LogoNomeFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
Func<FileData, Task> processFile = async fileData =>
|
Func<FileData, Task> processFile = async fileData =>
|
||||||
{
|
{
|
||||||
using var logoCopy = logoBmp.Clone(new Rectangle(0, 0, logoBmp.Width, logoBmp.Height),
|
Bitmap logoCopy = logoBmp is null
|
||||||
logoBmp.PixelFormat);
|
? null
|
||||||
|
: logoBmp.Clone(new Rectangle(0, 0, logoBmp.Width, logoBmp.Height), logoBmp.PixelFormat);
|
||||||
|
|
||||||
var imgState = new ImageState
|
var imgState = new ImageState
|
||||||
{
|
{
|
||||||
|
|
@ -81,26 +82,28 @@ namespace MaddoShared
|
||||||
DestDir = fileData.Directory,
|
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
|
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");
|
// Dispose the clone if it was created
|
||||||
throw;
|
logoCopy?.Dispose();
|
||||||
}
|
}
|
||||||
// finally
|
|
||||||
// {
|
|
||||||
// imgCreator = null;
|
|
||||||
// }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.LinearExecution)
|
if (options.LinearExecution)
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0-windows</TargetFramework>
|
<TargetFramework>net10.0-windows</TargetFramework>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net9.0-windows</TargetFramework>
|
<TargetFramework>net10.0-windows</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue