ASP.net VB 定时器

发布于 2024-09-05 07:02:48 字数 360 浏览 6 评论 0原文

我希望能够在 ASP.net (VBscript) 中计算页面加载时间。将 Trace="true" 添加到页面指令很好,但我需要实际计时事件并将其存储在变量中。

在 ASP 中,使用 Timer 对象很容易,但在 .net 中我在 Google 上找不到任何东西。

我需要一些类似的东西:

Dim startTime
Dim endTime

startTime = now()
doBigFunction()
endTime = now()
response.write("That took " & endTime - startTime & " milliseconds")

干杯!

I would like to be able to time a page load time in ASP.net (VBscript). Adding Trace="true" to the page directive is nice, but I need to actually time an event and store it in a variable.

In ASP it was easy with the Timer object, but in .net I can't find anything on Google.

I need something along the lines of:

Dim startTime
Dim endTime

startTime = now()
doBigFunction()
endTime = now()
response.write("That took " & endTime - startTime & " milliseconds")

Cheers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

兔小萌 2024-09-12 07:02:48

尝试使用秒表

    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(elapsedTime, "RunTime")

您不必计算,如果调用 stopWatch.Reset() 则可以重用它

从这里获取示例: http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

Try a StopWatch

    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(elapsedTime, "RunTime")

You don't have to calculate and you can reuse it if you call stopWatch.Reset()

Took the example from here: http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

冷︶言冷语的世界 2024-09-12 07:02:48

DataTime 类中有一个 DateTime.Now 静态成员可以执行您希望它执行的操作:

    Dim startTime As DateTime
    Dim endTime As DateTime

    startTime = DateTime.Now
    For i = 0 To 100000000
        Dim j As Integer = i * 2
    Next
    endTime = DateTime.Now
    Dim result As TimeSpan = endTime - startTime
    Console.WriteLine(result.Milliseconds)

There is a DateTime.Now static member of the DataTime class that does what you want it to do:

    Dim startTime As DateTime
    Dim endTime As DateTime

    startTime = DateTime.Now
    For i = 0 To 100000000
        Dim j As Integer = i * 2
    Next
    endTime = DateTime.Now
    Dim result As TimeSpan = endTime - startTime
    Console.WriteLine(result.Milliseconds)
怀念你的温柔 2024-09-12 07:02:48

对于此级别,您可以使用 DateTime.Now< /code>属性。 TimeSpan 是区别两个 DateTime 值之间。

为了获得更准确的结果,您需要秒表

For this level you can use the DateTime.Now property. A TimeSpan is the difference between two DateTime values.

For something more accurate you need the Stopwatch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文