mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
WorkQueue Threads swapped for tasks
This commit is contained in:
parent
a0328fef93
commit
de29af3277
@ -26,7 +26,7 @@ namespace Wabbajack.Common
|
||||
private readonly Subject<CPUStatus> _Status = new Subject<CPUStatus>();
|
||||
public IObservable<CPUStatus> Status => _Status;
|
||||
|
||||
public List<Thread> Threads { get; private set; }
|
||||
public List<Task> Tasks { get; private set; }
|
||||
|
||||
private CancellationTokenSource _cancel = new CancellationTokenSource();
|
||||
|
||||
@ -40,15 +40,13 @@ namespace Wabbajack.Common
|
||||
public WorkQueue(int? threadCount = null)
|
||||
{
|
||||
ThreadCount = threadCount ?? Environment.ProcessorCount;
|
||||
Threads = Enumerable.Range(1, ThreadCount)
|
||||
Tasks = Enumerable.Range(1, ThreadCount)
|
||||
.Select(idx =>
|
||||
{
|
||||
var thread = new Thread(() => ThreadBody(idx).Wait());
|
||||
thread.Priority = ThreadPriority.BelowNormal;
|
||||
thread.IsBackground = true;
|
||||
thread.Name = string.Format("Wabbajack_Worker_{0}", idx);
|
||||
thread.Start();
|
||||
return thread;
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
await ThreadBody(idx);
|
||||
});
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
@ -79,6 +77,10 @@ namespace Wabbajack.Common
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Error(ex, "Error in WorkQueue thread.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Report(string msg, int progress, bool isWorking = true)
|
||||
|
Loading…
Reference in New Issue
Block a user