2011-01-05 5 views

Répondre

4

Vérifiez la classe Timer.

Public Class Form1 
    Private T As Timer 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     T = New Timer() 
     AddHandler T.Tick, AddressOf TimerTicker 
     T.Interval = (1000 * 3) 'Every 3 seonds 
     T.Start() 
    End Sub 
    Private Sub TimerTicker(ByVal sender As Object, ByVal ev As EventArgs) 
     Trace.WriteLine("here") 
    End Sub 
End Class 
+0

Merci. Ça marche. – Voldemort

0

Parlez-vous de l'exécution d'une fonction à un certain intervalle de temps? Si c'est le cas, le contrôle Timer fonctionnera. Un rapide Google search vous donnera un certain nombre de tutoriels sur Timer.

0

Comment à propos de ceci: utiliser un temporisateur, et juste substituer la méthode que vous voulez pour l'alerte MessageBox. L'exemple suivant implémente un temporisateur d'intervalle simple qui déclenche une alarme toutes les cinq secondes. Lorsque l'alarme se produit, un MessageBox affiche le nombre de fois que l'alarme a démarré et invite l'utilisateur à indiquer si le minuteur doit continuer à fonctionner.

Vous trouverez plus de détails here.

Public Class Class1 
>  Private Shared WithEvents myTimer As New System.Windows.Forms.Timer() 
>  Private Shared alarmCounter As Integer = 1 
>  Private Shared exitFlag As Boolean = False  

> 
>  ' This is the method to run when the timer is raised. 
>  Private Shared Sub TimerEventProcessor(myObject As 
> Object, _ 
>           ByVal myEventArgs As EventArgs) _ 
>          Handles myTimer.Tick 
>   myTimer.Stop() 
> 
>   ' Displays a message box asking whether to continue running the 
> timer. 
>   If MessageBox.Show("Continue running?", "Count is: " & 
> alarmCounter, _ 
>        MessageBoxButtons.YesNo) = 
> DialogResult.Yes Then 
>    ' Restarts the timer and increments the counter. 
>    alarmCounter += 1 
>    myTimer.Enabled = True 
>   Else 
>    ' Stops the timer. 
>    exitFlag = True 
>   End If 
>  End Sub 
> 
>  Public Shared Sub Main() 
>   ' Adds the event and the event handler for the method that will 
>   ' process the timer event to the timer. 
> 
>   ' Sets the timer interval to 5 seconds. 
>   myTimer.Interval = 5000 
>   myTimer.Start() 
> 
>   ' Runs the timer, and raises the event. 
>   While exitFlag = False 
>    ' Processes all the events in the queue. 
>    Application.DoEvents() 
>   End While 
> 
>  End Sub  
> 
> End Class