do not discover while printing
This commit is contained in:
@@ -6,18 +6,40 @@ public class PrintServer
|
||||
private readonly IPrintService _printService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ConcurrentDictionary<string, PrinterQueue> _printerQueues;
|
||||
private readonly ReaderWriterLockSlim _printDiscoveryLock = new();
|
||||
|
||||
public PrintServer(IPrintService printService, ILogger logger)
|
||||
{
|
||||
_printService = printService;
|
||||
_logger = logger;
|
||||
_printerQueues = new ConcurrentDictionary<string, PrinterQueue>();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Acquires a read lock for print operations. Multiple print operations can run concurrently.
|
||||
/// </summary>
|
||||
public void EnterPrintLock() => _printDiscoveryLock.EnterReadLock();
|
||||
|
||||
/// <summary>
|
||||
/// Releases the read lock after a print operation completes.
|
||||
/// </summary>
|
||||
public void ExitPrintLock() => _printDiscoveryLock.ExitReadLock();
|
||||
|
||||
/// <summary>
|
||||
/// Acquires a write lock for discovery operations. This blocks until all print operations complete
|
||||
/// and prevents new print operations from starting.
|
||||
/// </summary>
|
||||
public void EnterDiscoveryLock() => _printDiscoveryLock.EnterWriteLock();
|
||||
|
||||
/// <summary>
|
||||
/// Releases the write lock after discovery completes.
|
||||
/// </summary>
|
||||
public void ExitDiscoveryLock() => _printDiscoveryLock.ExitWriteLock();
|
||||
|
||||
public void RegisterPrinter(string printerIp)
|
||||
{
|
||||
var queue = new PrinterQueue(printerIp, _printService, _logger);
|
||||
var queue = new PrinterQueue(printerIp, _printService, _logger, this);
|
||||
if (_printerQueues.TryAdd(printerIp, queue))
|
||||
{
|
||||
queue.Start();
|
||||
|
||||
Reference in New Issue
Block a user