Gestione status dei thread
This commit is contained in:
parent
d133917283
commit
9794ce1abb
35 changed files with 16112 additions and 30 deletions
|
|
@ -31,13 +31,13 @@ namespace MaddoShared
|
|||
public bool LinearExecution { get; set; }
|
||||
}
|
||||
|
||||
public async Task<string> CreaCatalogoParallel(Options options)
|
||||
public async Task<string> CreaCatalogoParallel(Options options, ConcurrentBag<string> results, EventHandler<Tuple<string,int>> updateEvent, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
// todo immagini counter
|
||||
//todo set label
|
||||
await CreaImmaginiParallel(options);
|
||||
await CreaImmaginiParallel(options, results, updateEvent, cancellationToken);
|
||||
|
||||
// todo set finito label
|
||||
stopwatch.Stop();
|
||||
|
|
@ -47,7 +47,7 @@ namespace MaddoShared
|
|||
|
||||
}
|
||||
|
||||
public async Task CreaImmaginiParallel(Options options)
|
||||
public async Task CreaImmaginiParallel(Options options, ConcurrentBag<string> results, EventHandler<Tuple<string, int>> updateEvent, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var dataToProcess = new List<FileData>();
|
||||
if (options.AggiornaSottodirectory && options.CreaSottocartelle)
|
||||
|
|
@ -114,6 +114,9 @@ namespace MaddoShared
|
|||
//imgC.CreaImmagineThread(d.File.Name);
|
||||
//imgC = null;
|
||||
}, CancellationToken.None, TaskCreationOptions.None, scheduler);
|
||||
|
||||
//int count = 0;
|
||||
|
||||
if (options.LinearExecution)
|
||||
{
|
||||
foreach (var task in test)
|
||||
|
|
@ -127,11 +130,23 @@ namespace MaddoShared
|
|||
{
|
||||
|
||||
|
||||
var opts = new ParallelOptions() { MaxDegreeOfParallelism = threads };
|
||||
//var opts = new ParallelOptions() { MaxDegreeOfParallelism = threads, CancellationToken = cancellationToken, TaskScheduler = scheduler};
|
||||
await dataToProcess.ParallelForEachAsync(async fileData =>
|
||||
{
|
||||
await new ImageCreatorSharp(fileData.File, fileData.Directory).CreaImmagineThread(fileData.File.Name);
|
||||
}, maxDegreeOfParallelism: threads);
|
||||
results.Add(fileData.File.Name);
|
||||
//count = Interlocked.Increment(ref count);
|
||||
try
|
||||
{
|
||||
updateEvent?.Invoke(this, new Tuple<string, int>(fileData.File.Name, dataToProcess.Count) );
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
|
||||
}, maxDegreeOfParallelism: threads, false, cancellationToken);
|
||||
|
||||
|
||||
//var throttler = new SemaphoreSlim(initialCount: threads);
|
||||
|
|
@ -156,7 +171,7 @@ namespace MaddoShared
|
|||
else
|
||||
{
|
||||
|
||||
var asdf = SplitList(dataToProcess.ToList(), dataToProcess.Count() / options.ChunksSize).ToList();
|
||||
var asdf = SplitList(dataToProcess.ToList(), dataToProcess.Count()).ToList();
|
||||
//var sadf = asdf[0];
|
||||
|
||||
//var sadf1 = asdf[1];
|
||||
|
|
@ -166,7 +181,18 @@ namespace MaddoShared
|
|||
await sdaf.ParallelForEachAsync(async fileData =>
|
||||
{
|
||||
await new ImageCreatorSharp(fileData.File, fileData.Directory).CreaImmagineThread(fileData.File.Name);
|
||||
}, maxDegreeOfParallelism: threads);
|
||||
results.Add(fileData.File.Name);
|
||||
//count = Interlocked.Increment(ref count);
|
||||
try
|
||||
{
|
||||
updateEvent?.Invoke(this, new Tuple<string, int>(fileData.File.Name, dataToProcess.Count));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}, maxDegreeOfParallelism: threads, false, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -189,6 +215,7 @@ namespace MaddoShared
|
|||
|
||||
|
||||
}
|
||||
|
||||
public static IEnumerable<List<T>> SplitList<T>(List<T> bigList, int nSize = 3)
|
||||
{
|
||||
for (int i = 0; i < bigList.Count; i += nSize)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue