简体   繁体   English

计时器控制vb.net

[英]Timer Control vb.net

I have written a function in a class which runs a report and outputs to excel. 我已经在运行报告并输出到excel的类中编写了一个函数。 I basically want to time it that how long it has took to generate the report. 我基本上想为生成报告花费多长时间。

Any help? 有什么帮助吗?

this code will help you to find the time required for your operation. 此代码将帮助您找到操作所需的时间。

Imports System
Imports System.Diagnostics
Imports System.Threading


Class Program

    Shared Sub Main(ByVal args() As String)
        Dim stopWatch As New Stopwatch()
        stopWatch.Start()
        Thread.Sleep(10000)
        stopWatch.Stop()
        ' Get the elapsed time as a TimeSpan value. 
        Dim ts As TimeSpan = stopWatch.Elapsed

        ' Format and display the TimeSpan value. 
        Dim elapsedTime As String = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
        Console.WriteLine( "RunTime " + elapsedTime)

    End Sub 'Main
End Class 'Program

if it is not enough,Click for Reference http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsed.aspx 如果还不够,请单击以获取参考。http://msdn.microsoft.com/zh-cn/library/system.diagnostics.stopwatch.elapsed.aspx

Easy Peezy. 轻松的Peezy。

You Don;t need a timer. 您不需要计时器。

Dim time1 as Date
Dim time2 as Date

'I start generating the report stuff here....
time1 = now
'blablalb
'blab lbah
'report.load (phseudo)

'I am now done with my report code.
time2 = now

msgbox("The time is took was: " & time2.subtract(time1).totalminutes & ":" & time2.subtract(time1).totalseconds)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM