Esempio n. 1
0
        /// <summary>
        /// 开启定时器
        /// </summary>
        /// <param name="repeat">If true sets a repetitive event, otherwise sets a one-shot</param>
        public void Start(bool repeat)
        {
            Stop();
            GC.KeepAlive(thisCB);

            //Set the timer type flags
            fuEvent f = fuEvent.TIME_CALLBACK_FUNCTION | (repeat ? fuEvent.TIME_PERIODIC : fuEvent.TIME_ONESHOT);

            lock (this)
            {
                id = timeSetEvent(uint.Parse((Interval).ToString()), 0, thisCB, UIntPtr.Zero, (uint)f);
                if (id == 0)
                {
                    throw new Exception("timeSetEvent error");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Start a timer instance
        /// </summary>
        /// <param name="ms">Timer interval in milliseconds</param>
        /// <param name="repeat">If true sets a repetitive event, otherwise sets a one-shot</param>
        public void Start(uint ms, bool repeat)
        {
            //Kill any existing timer
            Stop();

            //Set the timer type flags
            fuEvent f = fuEvent.TIME_CALLBACK_FUNCTION | (repeat ? fuEvent.TIME_PERIODIC : fuEvent.TIME_ONESHOT);

            lock (this)
            {
                id = timeSetEvent(ms, 0, thisCallBack, UIntPtr.Zero, (uint)f);
                if (id == 0)
                {
                    throw new Exception("timeSetEvent error");
                }
                //Debug.WriteLine("MMTimer " + id.ToString() + " started");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Start a timer instance
        /// </summary>
        /// <param name="ms">Timer interval in milliseconds</param>
        /// <param name="repeat">If true sets a repetitive event, otherwise sets a one-shot</param>
        public void Start(uint ms, bool repeat)
        {
            //Kill any existing timer
            Stop();

            //Set the timer type flags
            fuEvent f = fuEvent.TIME_CALLBACK_FUNCTION | (repeat ? fuEvent.TIME_PERIODIC : fuEvent.TIME_ONESHOT);

            lock (this)
            {
                id = timeSetEvent(ms, 0, thisCB, UIntPtr.Zero, (uint)f);
                if (id == 0)
                {
                    throw new Exception("timeSetEvent error");
                }
            }
            IsEnabled = true;
        }
Esempio n. 4
0
        /// <summary>
        /// Starts raising the System.Timers.MultimediaTimer.Elapsed event by
        /// setting System.Timers.MultimediaTimer.Enabled
        /// to true.
        ///
        /// Exceptions:
        ///   System.ArgumentOutOfRangeException:
        ///     The System.Timers.MultimediaTimer is created with an interval
        ///     equal to or greater than
        ///     System.Int32.MaxValue + 1, or set to an interval less than zero.
        /// </summary>
        public void Start()
        {
            lock (syncLock)
            {
                //Kill any existing timer
                Stop();
                Enabled = false;

                //Set the timer type flags
                fuEvent f = fuEvent.TIME_CALLBACK_FUNCTION | (AutoReset ? fuEvent.TIME_PERIODIC : fuEvent.TIME_ONESHOT);

                id = timeSetEvent(Interval, 0, timerCallback, UIntPtr.Zero, (uint)f);
                if (id == 0)
                {
                    throw new Exception("timeSetEvent error");
                }
                Debug.WriteLine("MultimediaTimer " + id.ToString() + " started");
                Enabled = true;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Start a timer instance
        /// </summary>
        /// <param name="ms">Timer interval in milliseconds</param>
        /// <param name="repeat">If true sets a repetitive event, otherwise sets a one-shot</param>
        public void Start(uint ms, bool repeat, TimerCallback CBFunc)
        {
            //Initialize the API callback
            thisCB = CBFunc;
            //Kill any existing timer
            Stop();
            timeBeginPeriod(1);
            //Set the timer type flags
            fuEvent f = fuEvent.TIME_CALLBACK_FUNCTION | (repeat ? fuEvent.TIME_PERIODIC : fuEvent.TIME_ONESHOT);

            lock (this)
            {
                id = timeSetEvent(ms, 0, thisCB, UIntPtr.Zero, (uint)f);
                if (id == 0)
                {
                    throw new Exception("timeSetEvent error");
                }
                Debug.WriteLine("MMTimer " + id.ToString() + " started");
            }
        }