コード例 #1
0
ファイル: Timer.cs プロジェクト: PikataGitHub/CSharp-OOP
        //Methods
        public void GetTimeWithDelegate()
        {
            GetSomeTime();
            Stopwatch timerToStop = new Stopwatch();

            timerToStop.Start();
            TimerDelegate delegateToCall = new TimerDelegate(GetSomeTime);

            do
            {
                if (timerToStop.Elapsed.Seconds != Seconds)
                {
                    continue;
                }
                delegateToCall.Invoke();
                timerToStop.Restart();
            } while (!Console.KeyAvailable);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="msg"></param>
        /// <param name="userCtx"></param>
        /// <param name="rsv1"></param>
        /// <param name="rsv2"></param>
        private void timerProc(UInt32 id, UInt32 msg, UIntPtr userCtx, UIntPtr rsv1, UIntPtr rsv2)
        {
            onTimer?.Invoke(this);

            /*
             * //クリティカルセクションでイベントハンドラを実行する場合
             * object syncObject = new object();
             * bool lockTaken = false;
             *
             * try {
             * Monitor.Enter(syncObject, ref lockTaken);
             * if (onTimer != null) {
             *
             *  //onTimer(this);
             * }
             * }
             * finally {
             * if (lockTaken ==true) Monitor.Exit(syncObject);
             * }
             */
        }