/// <summary> /// Schedules the next execution of the specified job /// </summary> /// <param name="job">The job.</param> internal void ScheduleNextExecution(IServiceJob job) { this._log.Debug(string.Format("SchedulingService.ScheduleNextExecution({0})", job.Name)); var currentTime = SystemTime.Now; var nextTime = job.NextOccurence(currentTime); PersistentTimer timer = new PersistentTimer((nextTime - currentTime).TotalMilliseconds, job.Name); timer.AutoReset = false; timer.Enabled = true; timer.Elapsed += (source, e) => { timer.Stop(); if (!job.IsExecuting && this.IsRunning) { job.Execute(); } this.ScheduleNextExecution(job); }; this._timers.Add(timer); if (this._jobs[job] != null) { this._jobs[job].Stop(); this._jobs[job].Dispose(); } this._jobs[job] = timer; // overwrite the timer. }
void Awake() { if (instance == null) { instance = this; } //DontDestroyOnLoad(this); minutes = defaultStartMinutes; if (PlayerPrefs.HasKey("TimeOnExit")) { milliseconds = PlayerPrefs.GetFloat("TimeOnExit"); minutes = (int)milliseconds / 60; milliseconds -= (minutes * 60); seconds = (int)milliseconds; milliseconds -= seconds; //PlayerPrefs.DeleteKey ("TimeOnExit"); } }