Example #1
0
        public void Stop()
        {
            if (this.sq != null)
            {
                this.sq.Shutdown();
                this.sq = null;
            }

            if (this.cancellationTokenSource != null)
            {
                this.cancellationTokenSource.Cancel();
            }

            this.started = false;
        }
Example #2
0
        /// <summary>
        /// Start the TimeTrigger after a delay
        /// </summary>
        /// <param name="delay">The delay</param>
        public void Start(TimeSpan delay)
        {
            // validate. cannot start twice
            if (this.started)
            {
                throw new Exception("Cannot start. Already started");
            }

            this.cancellationTokenSource = new CancellationTokenSource();
            this.started = true;

            // after a delay, start the scheduler
            Task.Delay(delay)
            .ContinueWith(t =>
            {
                // only if it was not disposed
                if (!this.cancellationTokenSource.IsCancellationRequested)
                {
                    this.sq = new SimpleQuartz();
                    sq.RepeatForever(this.Period, this.Data, o => this.OnTimerElapsed(this, o));
                }
            });
        }