private void QueryReportTimerCallback(object state) {
QueryReportCallbackHandlerQueryReportCallbackEvent(this, EventArgs.Empty);
}
private async void QueryReportCallbackHandlerQueryReportCallbackEventHandler(object sender, EventArgs e) {
if (await semaphoreQueryReportSlim.WaitAsync(10))
await queryReportsCore();
}
//CTOR
public MyClass() {
QueryReportCallbackEvent += QueryReportCallbackHandler;QueryReportCallbackEventHandler;
var QueryReportTimer = new Timer(QueryReportTimerCallback, null, TimeSpan.Zero, TimeSpan.FromSeconds(15));
}
event EventHandler QueryReportCallbackEvent = delegate { };
private void QueryReportTimerCallback(object state) {
QueryReportCallbackHandlerQueryReportCallbackEvent(this, EventArgs.Empty);
}
private async void QueryReportCallbackHandlerQueryReportCallbackEventHandler(object sender, EventArgs e) {
if (await semaphoreQueryReportSlim.WaitAsync(10))
await queryReportsCore();
}
private async Task queryReportsCore() {
try {
if (machineConfigurations != null) {
var tasks = machineConfigurations
.Where(x => x.QueryReport)
.Select(configuration => HandleReport(configuration));
await Task.WhenAll(tasks);
}
} catch (Exception e) {
logger.LogError(e, e.Message);
} finally {
semaphoreQueryReportSlim.Release();
}
}
private async Task HandleReport(MachineConfiguration configuration) {
if (configuration.IsConnectionValid) {
var queryReport = new QueryReport(configuration, ReportConfigurations, fileContainer, applicationConfiguration, logger);
await QueryAReport(configuration, queryReport);
}
}