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:
@ -26,7 +26,7 @@ namespace Wabbajack.Common
|
|||||||
private readonly Subject<CPUStatus> _Status = new Subject<CPUStatus>();
|
private readonly Subject<CPUStatus> _Status = new Subject<CPUStatus>();
|
||||||
public IObservable<CPUStatus> Status => _Status;
|
public IObservable<CPUStatus> Status => _Status;
|
||||||
|
|
||||||
public List<Thread> Threads { get; private set; }
|
public List<Task> Tasks { get; private set; }
|
||||||
|
|
||||||
private CancellationTokenSource _cancel = new CancellationTokenSource();
|
private CancellationTokenSource _cancel = new CancellationTokenSource();
|
||||||
|
|
||||||
@ -40,15 +40,13 @@ namespace Wabbajack.Common
|
|||||||
public WorkQueue(int? threadCount = null)
|
public WorkQueue(int? threadCount = null)
|
||||||
{
|
{
|
||||||
ThreadCount = threadCount ?? Environment.ProcessorCount;
|
ThreadCount = threadCount ?? Environment.ProcessorCount;
|
||||||
Threads = Enumerable.Range(1, ThreadCount)
|
Tasks = Enumerable.Range(1, ThreadCount)
|
||||||
.Select(idx =>
|
.Select(idx =>
|
||||||
{
|
{
|
||||||
var thread = new Thread(() => ThreadBody(idx).Wait());
|
return Task.Run(async () =>
|
||||||
thread.Priority = ThreadPriority.BelowNormal;
|
{
|
||||||
thread.IsBackground = true;
|
await ThreadBody(idx);
|
||||||
thread.Name = string.Format("Wabbajack_Worker_{0}", idx);
|
});
|
||||||
thread.Start();
|
|
||||||
return thread;
|
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +77,10 @@ namespace Wabbajack.Common
|
|||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Utils.Error(ex, "Error in WorkQueue thread.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Report(string msg, int progress, bool isWorking = true)
|
public void Report(string msg, int progress, bool isWorking = true)
|
||||||
|
Reference in New Issue
Block a user