Start operation implementation
This commit is contained in:
17
Hcs.WebApp/BackgroundServices/OperationExecutionService.cs
Normal file
17
Hcs.WebApp/BackgroundServices/OperationExecutionService.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
public class OperationExecutionService(OperationExecutionState state) : BackgroundService
|
||||
{
|
||||
private readonly OperationExecutionState state = state;
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(10000, stoppingToken);
|
||||
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Hcs.WebApp/BackgroundServices/OperationExecutionState.cs
Normal file
27
Hcs.WebApp/BackgroundServices/OperationExecutionState.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Hcs.WebApp.BackgroundServices
|
||||
{
|
||||
public class OperationExecutionState
|
||||
{
|
||||
private readonly ConcurrentQueue<Operation> operations = new();
|
||||
|
||||
public event Action<Operation> OnOperationStarted;
|
||||
|
||||
public void EnqueueOperation(Operation operation)
|
||||
{
|
||||
operations.Enqueue(operation);
|
||||
}
|
||||
|
||||
public bool TryDequeueOperation(out Operation operation)
|
||||
{
|
||||
return operations.TryDequeue(out operation);
|
||||
}
|
||||
|
||||
public void InvokeOnOperationStarted(Operation operation)
|
||||
{
|
||||
OnOperationStarted?.Invoke(operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user