Bonjour,

J'aurais besoin pour mon application d'un timer plus performant (interval ~1ms) que celui proposé par le framework (System.Windows.Form.Timer, ~18ms je crois).

J'ai commencé à écrire une classe mais mon problème c'est que quand je le lance, il monopolise les ressources, aucun traitement ne ce fait en parallèle.. J'ai testé avec un Application.DoEvents mais ça ne marche pas non plus..

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Imports System.Threading
 
Public Class CycleTimer
    Private Declare Function timeGetTime Lib "winmm.dll" () As Integer
    Private Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Integer) As Integer
    Private Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As Integer) As Integer
    Private state As TimerState = TimerState.Stop
    Private threadStart As ParameterizedThreadStart
    Private timeStart As Long = 0
 
 
    Sub New(start As ParameterizedThreadStart)
        Me.threadStart = start
    End Sub
 
    Sub [Start](Optional period As Integer = 1)
        state = TimerState.Start
        timeBeginPeriod(period)
        timeStart = timeGetTime
        While state = TimerState.Start
 
            threadStart.Invoke(New Object() {})
 
            Threading.Thread.Sleep(period)
        End While
        timeStart = -1
        timeEndPeriod(period)
    End Sub
 
    Sub [Stop]()
        state = TimerState.Stop
    End Sub
 
    Function GetTime() As Long
        If timeStart <> -1 Then
            Return timeGetTime - timeStart
        Else
            Return -1
        End If
    End Function
 
    Private Enum TimerState
        [Start]
        [Stop]
    End Enum
 
End Class
Merci de votre aide.