Пример #1
0
        /// <summary>
        ///     Start
        /// </summary>
        /// <param name="milliseconds"></param>
        /// <param name="dueTimeInMilliseconds"></param>
        public void Start(uint milliseconds, uint dueTimeInMilliseconds)
        {
            //Werte übernehmen
            Milliseconds = milliseconds;

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

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

            //QueueTimer Resolution setzen
            Win32.TimeBeginPeriod(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, Milliseconds, Win32.WT_EXECUTEINTIMERTHREAD);

            if (resultCreate)
            {
                //Handle im Speicher halten
                m_GCHandleTimer = GCHandle.Alloc(m_HandleTimer, GCHandleType.Pinned);
                //QueueTimer ist gestartet
                IsRunning = true;
            }
        }
Пример #2
0
        /// <summary>
        ///     Start
        /// </summary>
        /// <param name="milliseconds"></param>
        /// <param name="dueTimeInMilliseconds"></param>
        public void Start(uint milliseconds, uint dueTimeInMilliseconds)
        {
            //Werte übernehmen
            Milliseconds = milliseconds;

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

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

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

            //Versuche EventTimer zu starten
            m_TimerId = Win32.TimeSetEvent(Milliseconds, 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
                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);
        }