Beispiel #1
0
        private WaitHandle notifyObject;                                // Who do notify when object disposed

        //
        // Private constructor - used to ensure all constructors initialise
        // the object in the same way.
        //
        private Timer(TimerCallback callback, Object state)
        {
            //
            // Validate the parameters.
            //
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            //
            // If this is the first timer constructed allocate resources
            // for the timer thread and start it.
            //
            lock (typeof(Timer))
            {
                if (Timer.alarmClock == null)
                {
                    if (!Thread.CanStartThreads())
                    {
                        throw new NotImplementedException();
                    }
                    Timer.alarmClock               = new AlarmClock();
                    Timer.disposeQueue             = new System.Collections.Queue();
                    Timer.now                      = Timer.UtcMilliseconds();
                    Timer.threadWakeup             = new AutoResetEvent(false);
                    Timer.timerThread              = new Thread(new ThreadStart(Timer.Run));
                    Timer.timerThread.IsBackground = true;
                    Timer.timerThread.Start();
                }
            }
            //
            // Initialize the timer state.
            //
            lock (this)
            {
                this.disposed = false;
                this.alarm    = Timer.alarmClock.CreateAlarm(
                    new AlarmClock.AlarmExpiredHandler(this.fireTimer));
                this.callback = callback;
                this.state    = state;
            }
        }
Beispiel #2
0
		private WaitHandle			notifyObject;	// Who do notify when object disposed

		//
		// Private constructor - used to ensure all constructors initialise
		// the object in the same way.
		//
		private Timer(TimerCallback callback, Object state)
		{
			//
			// Validate the parameters.
			//
			if (callback == null)
				throw new ArgumentNullException("callback");
			//
			// If this is the first timer constructed allocate resources
			// for the timer thread and start it.
			//
			lock (typeof(Timer))
			{
				if (Timer.alarmClock == null)
				{
					if (!Thread.CanStartThreads())
						throw new NotImplementedException();
					Timer.alarmClock = new AlarmClock();
					Timer.disposeQueue = new System.Collections.Queue();
					Timer.now = Timer.UtcMilliseconds();
					Timer.threadWakeup = new AutoResetEvent(false);
					Timer.timerThread = new Thread(new ThreadStart(Timer.Run));
					Timer.timerThread.IsBackground = true;
					Timer.timerThread.Start();
				}
			}
			//
			// Initialize the timer state.
			//
			lock (this)
			{
				this.disposed = false;
				this.alarm = Timer.alarmClock.CreateAlarm(
					new AlarmClock.AlarmExpiredHandler(this.fireTimer));
				this.callback = callback;
				this.state = state;
			}
		}