common/Hardware/WaterMeter/WaterMeterCore/BatchActions/BatchCall.cs
2026-04-23 17:50:07 +02:00

37 lines
1019 B
C#

using System.Collections.Generic;
using System.Threading.Tasks;
namespace Xylem.Common.Hardware.WaterMeter.WaterMeterCore.BatchActions
{
/// <summary>
/// Applies an action to a list of meters in a separate thread
/// </summary>
public abstract class BatchCall
{
/// <summary>
/// Starts a new task for a list of meters
/// </summary>
/// <param name="meters"></param>
public void RunAction(IEnumerable<IMeter> meters)
{
var listOfTask = new List<Task>();
foreach (var meter in meters)
{
listOfTask.Add(Task.Factory.StartNew(() =>
{
DoSingleAction(meter);
}));
}
Task.WaitAll(listOfTask.ToArray());
}
/// <summary>
/// Apply a single action to a specific meter
/// </summary>
/// <param name="meter"></param>
public abstract void DoSingleAction(IMeter meter);
}
}