Get elapsed time since application start

前端 未结 1 1809
庸人自扰
庸人自扰 2021-01-03 20:22

I am porting an app from ActionScript3.0 (Flex) to C# (WPF).AS3.0 has got a handy utility called getTimer() which returns time since Flash Virtual machine start in milliseco

相关标签:
1条回答
  • 2021-01-03 20:40

    Process.GetCurrentProcess().StartTime is your friend.

    ..so to get elapsed time since start:

    DateTime.UtcNow - Process.GetCurrentProcess().StartTime.ToUniversalTime()
    

    alternatively, if you need more definition, System.Diagnostics.Stopwatch might be preferable. If so, start a stopwatch when your app starts:

    Stopwatch sw = Stopwatch.StartNew();
    

    then query the sw.Elapsed property during your execution run.

    0 讨论(0)
提交回复
热议问题