Share via


Proprietà Timer

Aggiornamento: novembre 2007

Restituisce un valore Double che rappresenta il numero di secondi trascorsi dalla mezzanotte.

ReadOnly Public Property Timer() As Double

Note

La proprietà Timer restituisce sia i secondi che i millisecondi dopo la mezzanotte. I secondi sono la parte intera del valore restituito, mentre i millisecondi sono la parte frazionaria.

Esempio

In questo esempio la proprietà Timer viene utilizzata per sospendere l'applicazione. Durante la sospensione possono essere eseguite altre attività di elaborazione.

Public Sub waitFiveSeconds()
    If TimeOfDay >= #11:59:55 PM# Then
        MsgBox("The current time is within 5 seconds of midnight" & _
            vbCrLf & "The timer returns to 0.0 at midnight")
        Return
    End If
    Dim start, finish, totalTime As Double
    If (MsgBox("Press Yes to pause for 5 seconds", MsgBoxStyle.YesNo)) _
        = MsgBoxResult.Yes Then
        start = Microsoft.VisualBasic.DateAndTime.Timer
        ' Set end time for 5-second duration.
        finish = start + 5.0
        Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
        ' Do other processing while waiting for 5 seconds to elapse.
        Loop
        totalTime = Microsoft.VisualBasic.DateAndTime.Timer - start
        MsgBox("Paused for " & totalTime & " seconds")
    End If
End Sub

È necessario specificare la proprietà Timer con lo spazio dei nomi Microsoft.VisualBasic, in quanto Timer è anche una classe definita negli spazi dei nomi System.Threading, System.Timers e System.Windows.Forms.

Requisiti

Spazio dei nomi:Microsoft.VisualBasic

**Modulo:**DateAndTime

**Assembly:**Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Poiché Timer è un membro di un modulo, anziché di una classe, non è necessario creare un oggetto su cui accedere a Timer.

Vedere anche

Riferimenti

Funzione Randomize (Visual Basic)

Proprietà TimeOfDay

Proprietà Today

System

System.Windows.Forms

DateTime

ArgumentException

ArgumentOutOfRangeException