Miniprofiler.Current method does not return the ti

2019-07-15 12:17发布

问题:

I'm trying to get time with this code using MiniProfiler.

var profiler = StackExchange.Profiling.MiniProfiler.Current;

But it returns 0 ms in result. How to get current time in miniprofiler.

This method gives me result with MiniProfiler version 2.1.0.

Right now I am using MiniProfiler version 3.1.1.139.

回答1:

You can get the total elapsed time for the current MiniProfiler by accessing StackExchange.Profiling.MiniProfiler.Current.DurationMilliseconds - but only after the current MiniProfiler has been stopped (it is only populated at that point). Before it is stopped, an active MiniProfiler instance will not have this property set.

There is no way right now to get the elapsed time for an active MiniProfiler instance. There is an internal property called ElapsedTicks but as this is an internal property, you cannot access it outside of the MiniProfiler assembly.

If it is super-important for you to be able to access this data for an active MiniProfiler instance, than you could fork the current build and switch the property to be public (though before you do this I would question what your use case is - perhaps there is another way to achieve this).