49 lines
1.0 KiB
C#
49 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Timers;
|
|
|
|
namespace BlaServApp.UI.Services
|
|
{
|
|
/// <summary>
|
|
/// Timer a consumo
|
|
/// https://wellsb.com/csharp/aspnet/blazor-timer-navigate-programmatically/
|
|
/// (da verificare)
|
|
/// </summary>
|
|
public class BlazorTimer
|
|
{
|
|
#region Private Fields
|
|
|
|
private Timer _timer;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Events
|
|
|
|
public event Action OnElapsed;
|
|
|
|
#endregion Public Events
|
|
|
|
#region Private Methods
|
|
|
|
private void NotifyTimerElapsed(Object source, ElapsedEventArgs e)
|
|
{
|
|
OnElapsed?.Invoke();
|
|
_timer.Dispose();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Public Methods
|
|
|
|
public void SetTimer(double interval)
|
|
{
|
|
_timer = new Timer(interval);
|
|
_timer.Elapsed += NotifyTimerElapsed;
|
|
_timer.Enabled = true;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |