我在类中编写了一个函数,它运行报告并输出到excel。 我基本上想知道生成报告需要多长时间。
任何帮助?
答案 0 :(得分:1)
此代码可帮助您找到操作所需的时间。
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
如果还不够,请点击参考http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsed.aspx
答案 1 :(得分:0)
Easy Peezy。
你不需要计时器。
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)