Aggiunto progetto gestione TaskScheduler
This commit is contained in:
+51
-1
@@ -1,4 +1,5 @@
|
||||
using SteamWare;
|
||||
using Steamware.Scheduler;
|
||||
using SteamWare;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -95,5 +96,54 @@ namespace TestBench
|
||||
}
|
||||
lblRedCDV.Text = sb.ToString();
|
||||
}
|
||||
|
||||
private void btnStartSched_Click(object sender, EventArgs e)
|
||||
{
|
||||
// avvia uno scheduler che apre una messagebox secondo programmazione impostata...
|
||||
|
||||
// For Interval in Minutes
|
||||
// This Scheduler will start at 22:00 and call after every 30 Minutes
|
||||
// IntervalInSeconds(start_hour, start_minute, minutes)
|
||||
|
||||
// calcolo istante dal PROSSIMO minuto
|
||||
DateTime avvio = DateTime.Now;
|
||||
lblStartTimer.Text = $"Avvio timer: {avvio:ddd yyyy-MM-dd HH:mm:ss}";
|
||||
avvio = avvio.AddMinutes(1).AddSeconds(-avvio.Second);
|
||||
lblNextSched.Text = $"Scadenza timer: {avvio:ddd yyyy-MM-dd HH:mm:ss}";
|
||||
|
||||
clockTimer.Start();
|
||||
|
||||
// calcolo periodo in minuti guardando quanto selezionato
|
||||
int ore = 0;
|
||||
int min = 0;
|
||||
int sec = 0;
|
||||
int.TryParse(txtOre.Text, out ore);
|
||||
int.TryParse(txtMin.Text, out min);
|
||||
int.TryParse(txtSec.Text, out sec);
|
||||
// calcolo
|
||||
double intSecondi = ore * 60 * 60 + min * 60 + sec;
|
||||
|
||||
TaskScheduler.IntervalInSeconds(avvio.Hour, avvio.Minute, intSecondi,
|
||||
() =>
|
||||
{
|
||||
DateTime adesso = DateTime.Now;
|
||||
|
||||
// Initializes the variables to pass to the MessageBox.Show method.
|
||||
string message = $"E' scattato il timer alle ore {DateTime.Now}.";
|
||||
string caption = "Timer Elapsed";
|
||||
MessageBoxButtons buttons = MessageBoxButtons.OK;
|
||||
DialogResult result;
|
||||
|
||||
lblNextSched.Text = $"Scadenza timer: {adesso.AddSeconds(intSecondi):ddd yyyy-MM-dd HH:mm:ss}";
|
||||
// Displays the MessageBox.
|
||||
result = MessageBox.Show(message, caption, buttons);
|
||||
});
|
||||
}
|
||||
|
||||
private void clockTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
DateTime adesso = DateTime.Now;
|
||||
lblClock.Text = $"Clock: {adesso:ddd yyyy-MM-dd HH:mm:ss}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user