Domanda

In questo link mostra comeDetermina se è in esecuzione un timer.Per me non funziona.

Ho il timer dichiarato in una classe statica come mostrato

public static class ServiceGlobals // Globals
{

    public static System.Timers.Timer _timer = new System.Timers.Timer();
}
.

}

All'avvio del mio servizio, ho impostato le proprietà del timer

 protected override void OnStart(string[] args)
        {                  

                    ServiceGlobals._timer.AutoReset = false;
                    ServiceGlobals._timer.Interval = (3000);
                    ServiceGlobals._timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed);
                    ServiceGlobals._timer.Enabled = true;
                    ServiceGlobals._timer.Start(); // Start timer                  
        }
.

Allora controllo se è in esecuzione in uno dei miei metodi, ma anche quando è in esecuzione il codice è sempre falso

if (ServiceGlobals._timer.Enabled) // Check if the timer is running
{
    // Return error.........

}
.

È stato utile?

Soluzione

Devi aver perso questa parte del thread che hai collegato:

"Se TIMER.AUTORESET è vero, quindi abilitato verrà automaticamente impostato su false la prima volta che il timer scade."

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top