예제 #1
0
        /// <summary>
        ///     Start
        /// </summary>
        /// <param name="milliseconds"></param>
        /// <param name="dueTimeInMilliseconds"></param>
        public void Start(uint milliseconds, uint dueTimeInMilliseconds)
        {
            //Werte übernehmen
            m_Milliseconds = milliseconds;

            //Timer Auflösung ermitteln
            var tc = new Win32.TimeCaps();

            Win32.TimeGetDevCaps(ref tc, (uint)Marshal.SizeOf(typeof(Win32.TimeCaps)));
            m_ResolutionInMilliseconds = Math.Max(tc.wPeriodMin, 0);

            //Timer Resolution setzen
            Win32.TimeBeginPeriod(m_ResolutionInMilliseconds);

            //Versuche EventTimer zu starten
            m_TimerId = Win32.TimeSetEvent(m_Milliseconds, m_ResolutionInMilliseconds, m_DelegateTimeEvent,
                                           ref m_UserData, Win32.TIME_PERIODIC);
            if (m_TimerId > 0)
            {
                //Handle im Speicher halten
                m_GCHandleTimer = GCHandle.Alloc(m_TimerId, GCHandleType.Pinned);
                //QueueTimer ist gestartet
                m_IsRunning = true;
            }
        }
예제 #2
0
        /// <summary>
        ///     Start
        /// </summary>
        /// <param name="milliseconds"></param>
        /// <param name="dueTimeInMilliseconds"></param>
        public void Start(uint milliseconds, uint dueTimeInMilliseconds)
        {
            //Werte übernehmen
            m_Milliseconds = milliseconds;

            //QueueTimer Auflösung ermitteln
            var tc = new Win32.TimeCaps();

            Win32.TimeGetDevCaps(ref tc, (uint)Marshal.SizeOf(typeof(Win32.TimeCaps)));
            m_ResolutionInMilliseconds = Math.Max(tc.wPeriodMin, 0);

            //QueueTimer Resolution setzen
            Win32.TimeBeginPeriod(m_ResolutionInMilliseconds);

            //QueueTimer Queue erstellen
            m_HandleTimerQueue   = Win32.CreateTimerQueue();
            m_GCHandleTimerQueue = GCHandle.Alloc(m_HandleTimerQueue);

            //Versuche QueueTimer zu starten
            var resultCreate = Win32.CreateTimerQueueTimer(out m_HandleTimer, m_HandleTimerQueue, m_DelegateTimerProc,
                                                           IntPtr.Zero, dueTimeInMilliseconds, m_Milliseconds, Win32.WT_EXECUTEINTIMERTHREAD);

            if (resultCreate)
            {
                //Handle im Speicher halten
                m_GCHandleTimer = GCHandle.Alloc(m_HandleTimer, GCHandleType.Pinned);
                //QueueTimer ist gestartet
                m_IsRunning = true;
            }
        }
예제 #3
0
        /// <summary>
        ///     ResetResolution
        /// </summary>
        public static void ResetResolution()
        {
            //QueueTimer Auflösung ermitteln
            var tc = new Win32.TimeCaps();

            Win32.TimeGetDevCaps(ref tc, (uint)Marshal.SizeOf(typeof(Win32.TimeCaps)));
            var resolution = Math.Max(tc.wPeriodMin, 0);

            //QueueTimer Resolution deaktivieren
            Win32.TimeBeginPeriod(resolution);
        }