65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using System.Diagnostics;
|
|
|
|
namespace EgwCoreLib.BlazorTest.Pages
|
|
{
|
|
public partial class TestProgress
|
|
{
|
|
#region Protected Properties
|
|
|
|
protected double expTime { get; set; } = 5;
|
|
protected int numSteps { get; set; } = 10;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string realTime = "";
|
|
|
|
protected async Task StartLongTimer()
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
maxVal = numSteps * 10;
|
|
double stdWait = expTime / numSteps;
|
|
int nextWait = 1000;
|
|
int stepVal = maxVal / numSteps;
|
|
// imposto i valori x progress..
|
|
expTimeMSec = (int)(stdWait * 1000);
|
|
//nextVal = stepVal;
|
|
for (int currStep = 1; currStep <= numSteps; currStep++)
|
|
{
|
|
// aggiorno valori
|
|
currVal = (currStep - 1) * stepVal;
|
|
nextVal = currStep * stepVal;
|
|
// se max mi fermo...
|
|
if (nextVal > maxVal)
|
|
{
|
|
nextVal = maxVal;
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
// simulo ritardo importante (da 0 a 2 volte)
|
|
nextWait = (int)(rnd.Next(100, 2000) * stdWait);
|
|
// attendo step successivi...
|
|
await Task.Delay(nextWait);
|
|
}
|
|
await Task.Delay(1);
|
|
currVal = maxVal;
|
|
sw.Stop();
|
|
realTime = $"Real: {sw.Elapsed.TotalSeconds:N3}s";
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private int currVal = 100;
|
|
private int expTimeMSec = 10000;
|
|
private int maxVal = 100;
|
|
private int nextVal = 100;
|
|
private Random rnd = new Random();
|
|
private string titleMsg = "SIM Progress";
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |