mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-11 15:26:55 +03:00
parent
5c2eb68188
commit
3df38f0e90
@ -5,6 +5,7 @@ using NAPS2.ImportExport;
|
||||
using NAPS2.ImportExport.Images;
|
||||
using NAPS2.Platform.Windows;
|
||||
using NAPS2.Recovery;
|
||||
using NAPS2.Remoting.Worker;
|
||||
using NAPS2.Sdk.Tests;
|
||||
using NAPS2.Sdk.Tests.Asserts;
|
||||
using NAPS2.Update;
|
||||
@ -36,6 +37,7 @@ public class DesktopControllerTests : ContextualTests
|
||||
private readonly DesktopFormProvider _desktopFormProvider;
|
||||
private readonly Mock<IScannedImagePrinter> _scannedImagePrinter;
|
||||
private readonly ThumbnailController _thumbnailController;
|
||||
private readonly Mock<IWorkerFactory> _workerFactory;
|
||||
|
||||
public DesktopControllerTests()
|
||||
{
|
||||
@ -59,6 +61,7 @@ public class DesktopControllerTests : ContextualTests
|
||||
_desktopFormProvider = new DesktopFormProvider();
|
||||
_scannedImagePrinter = new Mock<IScannedImagePrinter>();
|
||||
_thumbnailController = new ThumbnailController(_thumbnailRenderQueue, _config);
|
||||
_workerFactory = new Mock<IWorkerFactory>();
|
||||
_desktopController = new DesktopController(
|
||||
ScanningContext,
|
||||
_imageList,
|
||||
@ -78,7 +81,8 @@ public class DesktopControllerTests : ContextualTests
|
||||
_desktopImagesController,
|
||||
_desktopScanController.Object,
|
||||
_desktopFormProvider,
|
||||
_scannedImagePrinter.Object
|
||||
_scannedImagePrinter.Object,
|
||||
_workerFactory.Object
|
||||
);
|
||||
|
||||
_operationFactory.Setup(x => x.Create<RecoveryOperation>()).Returns(
|
||||
|
@ -5,6 +5,7 @@ using NAPS2.ImportExport.Images;
|
||||
using NAPS2.Platform.Windows;
|
||||
using NAPS2.Recovery;
|
||||
using NAPS2.Remoting;
|
||||
using NAPS2.Remoting.Worker;
|
||||
using NAPS2.Scan;
|
||||
using NAPS2.Update;
|
||||
|
||||
@ -30,6 +31,7 @@ public class DesktopController
|
||||
private readonly IDesktopScanController _desktopScanController;
|
||||
private readonly DesktopFormProvider _desktopFormProvider;
|
||||
private readonly IScannedImagePrinter _scannedImagePrinter;
|
||||
private readonly IWorkerFactory _workerFactory;
|
||||
|
||||
private bool _closed;
|
||||
private bool _initialized;
|
||||
@ -43,7 +45,7 @@ public class DesktopController
|
||||
ImageClipboard imageClipboard, ImageListActions imageListActions,
|
||||
DialogHelper dialogHelper,
|
||||
DesktopImagesController desktopImagesController, IDesktopScanController desktopScanController,
|
||||
DesktopFormProvider desktopFormProvider, IScannedImagePrinter scannedImagePrinter)
|
||||
DesktopFormProvider desktopFormProvider, IScannedImagePrinter scannedImagePrinter, IWorkerFactory workerFactory)
|
||||
{
|
||||
_scanningContext = scanningContext;
|
||||
_imageList = imageList;
|
||||
@ -63,6 +65,7 @@ public class DesktopController
|
||||
_desktopScanController = desktopScanController;
|
||||
_desktopFormProvider = desktopFormProvider;
|
||||
_scannedImagePrinter = scannedImagePrinter;
|
||||
_workerFactory = workerFactory;
|
||||
}
|
||||
|
||||
public bool SkipRecoveryCleanup { get; set; }
|
||||
@ -167,6 +170,7 @@ public class DesktopController
|
||||
}
|
||||
_closed = true;
|
||||
_thumbnailController.Dispose();
|
||||
_workerFactory.Dispose();
|
||||
}
|
||||
|
||||
public bool PrepareForClosing(bool userClosing)
|
||||
|
@ -127,6 +127,7 @@ public class ThumbnailRenderQueue : IDisposable
|
||||
_renderThumbnailsCompleteHandle.Set();
|
||||
_renderThumbnailsWaitHandle.WaitOne();
|
||||
}
|
||||
worker?.Dispose();
|
||||
}
|
||||
|
||||
private IMemoryImage RenderThumbnailWithWorker(WorkerContext worker, ProcessedImage imageToRender,
|
||||
|
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// A factory interface to spawn NAPS2.Worker.exe instances as needed.
|
||||
/// </summary>
|
||||
public interface IWorkerFactory
|
||||
public interface IWorkerFactory : IDisposable
|
||||
{
|
||||
void Init();
|
||||
WorkerContext Create(WorkerType workerType);
|
||||
|
@ -161,4 +161,16 @@ public class WorkerFactory : IWorkerFactory
|
||||
worker.Service.Init(_fileStorageManager.FolderPath);
|
||||
return worker;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_workerQueues == null) return;
|
||||
foreach (var queue in _workerQueues.Values)
|
||||
{
|
||||
while (queue.TryTake(out var worker))
|
||||
{
|
||||
worker.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user