Correzione timer x considerare tempo di esecuzione

This commit is contained in:
Samuele Locatelli
2022-09-15 09:51:24 +02:00
parent 37a62a34ae
commit ce92f70eb0
3 changed files with 30 additions and 6 deletions
+14 -5
View File
@@ -2,6 +2,7 @@
using Microsoft.JSInterop;
using MP.Data.DatabaseModels;
using MP.SPEC.Data;
using System.Diagnostics;
namespace MP.SPEC.Components
{
@@ -13,8 +14,6 @@ namespace MP.SPEC.Components
public bool LiveUpdate { get; set; }
private bool _liveUpdate { get; set; }
[Parameter]
public int MaxRecord
{
@@ -84,7 +83,6 @@ namespace MP.SPEC.Components
public void Dispose()
{
//aTimer.Elapsed -= ElapsedTimer;
aTimer.Stop();
aTimer.Dispose();
}
@@ -93,12 +91,22 @@ namespace MP.SPEC.Components
{
if (!isLoading && LiveUpdate)
{
aTimer.Stop();
// inizio misura esecuzione
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
var pUpd = Task.Run(async () =>
{
await Task.Delay(1);
await InvokeAsync(() => reloadData(true));
});
pUpd.Wait();
// misuro tempo esecuzione
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
int deltaTime = tOutPeriod - (int)ts.TotalMilliseconds;
aTimer.Interval = deltaTime > 100 ? deltaTime : 100;
aTimer.Start();
}
}
@@ -116,9 +124,10 @@ namespace MP.SPEC.Components
isLoading = false;
}
private int tOutPeriod { get; set; } = 2000;
public void StartTimer()
{
int tOutPeriod = 2000;
//int.TryParse(Configuration["ReloadStatusTimer"], out tOutPeriod);
aTimer = new System.Timers.Timer(tOutPeriod);
aTimer.Elapsed += ElapsedTimer;
@@ -175,7 +184,7 @@ namespace MP.SPEC.Components
#region Private Fields
private static System.Timers.Timer aTimer = null!;
private int _maxRecord = 300;
private int _maxRecord = 100;
private string _selFlux = "*";
private string _selMacchina = "*";
private FluxLog? currRecord = null;
+1 -1
View File
@@ -61,7 +61,7 @@
</div>
</div>
<div class="card-body">
<ListPARAMS SelMacchina="@selMacchina" SelFlux="@selFlux" LiveUpdate="@liveUpdate"></ListPARAMS>
<ListPARAMS SelMacchina="@selMacchina" SelFlux="@selFlux" LiveUpdate="@liveUpdate" MaxRecord="@maxRecord"></ListPARAMS>
</div>
<div class="card-footer py-1">
<DataPager @ref="pagerODL" PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="totalCount" showLoading="isLoading" />
+15
View File
@@ -156,6 +156,21 @@ namespace MP.SPEC.Pages
set => MsgService.totalCount = value;
}
private int maxRecord
{
get => _maxRecord;
set
{
_maxRecord = value;
if (value > 100 && liveUpdate)
{
liveUpdate = false;
}
}
}
private int _maxRecord = 100;
#endregion Private Properties
#region Private Methods