Это мое основное:
Код: Выделить всё
static void Main()
{
if (Debugger.IsAttached)
{
Console.WriteLine("Il servizio è in modalità debug.");
MyService service = new MyService();
service.OnStart(null);
Console.WriteLine("Premi un tasto per arrestare il servizio...");
Thread.Sleep(Timeout.Infinite);
service.OnStop();
}
else
{
Log("Il servizio non è in modalità debug, lo avvio come servizio Windows");
ServiceBase[] ServicesToRun = new ServiceBase[] { new MyService() };
ServiceBase.Run(ServicesToRun);
}
}
Код: Выделить всё
public new void OnStart(string[] args)
{
// Calcola il tempo fino alle 7:00 AM del giorno successivo
base.OnStart(args);
Log("arrivo qua");
// Imposta il timer per eseguire l'operazione ogni giorno alle 7:00 AM
_timer = new Timer();
_timer.Elapsed += TimerElapsed;
var configParams = LeggiParametri(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.txt"));
SetGiorniParam(configParams.Item1); // Imposta il numero di giorni
SetEmailTo(configParams.Item2); // Imposta le email da inviare
SetEmailCC(configParams.Item3);
TimeSpan timeUntilNextRun = GetTimeUntilNextRun();
_timer.Interval = timeUntilNextRun.TotalMilliseconds;
_timer.Start();
EseguiOperazione();
WriteToLog("Il servizio è stato avviato.");
}
Можете ли вы мне помочь?
Подробнее здесь: https://stackoverflow.com/questions/791 ... -after-run
Мобильная версия