DateAndTime.Timer Proprietà

Definizione

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

public:
 static property double Timer { double get(); };
public static double Timer { get; }
static member Timer : double
Public ReadOnly Property Timer As Double

Valore della proprietà

Valore che rappresenta il numero di secondi trascorsi dalla mezzanotte.

Esempio

In questo esempio viene utilizzata la Timer proprietà per sospendere l'applicazione. Può eseguire altre elaborazioni durante la pausa.

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

Si noti che è necessario qualificare la proprietà Timer con lo spazio dei nomi Microsoft.VisualBasic, perché Timer è anche una classe definita negli spazi dei nomi System.Threading, System.Timers e System.Windows.Forms.

Commenti

La Timer proprietà restituisce sia i secondi che i millisecondi dalla mezzanotte più recente. I secondi si trovano nella parte integrante del valore restituito e i millisecondi si trovano nella parte frazionaria.

Si applica a

Vedi anche