30 October 2017

Utilizzare un TimeSpan per cronometrare l'esecuzione del codice

    Sub Cronometra()

        Dim start_time As DateTime = Date.Now

        '-- FACCIAMO FINTA DI FAR QUALCOSA...
        Threading.Thread.Sleep(1000 * 10)

        Dim stop_time As DateTime = Date.Now

        Dim elapsed_time As TimeSpan = stop_time.Subtract(start_time)

        With elapsed_time
            Dim s As String = String.Format("Eseguito in {0:00}:{1:00}:{2:00}",
                                            .TotalHours,
                                            .Minutes,
                                            .Seconds
                                            )

            Console.WriteLine(s)
        End With

    End Sub