Files
laatzen/Common/Hardware/WaterMeter/WaterMeterCore/BatchActions/BatchCall.cs
T
2021-10-01 11:09:20 +02:00

39 lines
1021 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="forMeters"></param>
public void RunAction(List<IMeter> forMeters)
{
var listOfTask = new List<Task>();
foreach (var item in forMeters)
{
listOfTask.Add(Task.Factory.StartNew(() =>
{
DoSingleAction(item);
}));
}
Task.WaitAll(listOfTask.ToArray());
}
/// <summary>
/// Apply a single action to a specific meter
/// </summary>
/// <param name="meter"></param>
public abstract void DoSingleAction(IMeter meter);
}
}