本文整理汇总了C#中Stopwatch.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Stopwatch.GetType方法的具体用法?C# Stopwatch.GetType怎么用?C# Stopwatch.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateStopwatchAtElapsed
// https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201312/20131224
// X:\jsc.svn\core\ScriptCoreLib.Ultra\ScriptCoreLib.Ultra\Ultra\Library\StringConversionsForStopwatch.cs
public static Stopwatch CreateStopwatchAtElapsed(TimeSpan t)
{
// http://msdn.microsoft.com/en-us/magazine/cc163996.aspx
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx
var Frequency = Stopwatch.Frequency;
//Console.WriteLine("enter CLR_StringConversionsForStopwatchExtensions.CreateStopwatchAtElapsed. this shall only happen in clr. " + new { Debugger.IsAttached });
// Stopwatch.GetTimestamp() 0x0000001fa3aa613e long
//Stopwatch.IsHighResolution true bool
//var nn = new Stopwatch();
//nn.Start();
var n = new Stopwatch();
// we will simulate n.Start();
var startTimeStamp = n.GetType().GetField("startTimeStamp", Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Instance);
var ticks = Stopwatch.GetTimestamp();
var elapsed = t.TotalMilliseconds * Stopwatch.Frequency / 1000;
var start = ticks - (long)elapsed;
//System.Threading.Thread.Sleep(t);
//var stop = Stopwatch.GetTimestamp();
//var elapsed = stop - ticks;
// elapsed * 1000 / Frequency = 211 long
//ticks -= t.Ticks;
startTimeStamp.SetValue(
n, start
);
n.GetType().GetField("isRunning", Reflection.BindingFlags.NonPublic | Reflection.BindingFlags.Instance).SetValue(
n, true
);
//Console.WriteLine("CLR_StringConversionsForStopwatchExtensions.CreateStopwatchAtElapsed " + new { n.ElapsedMilliseconds, n.IsRunning });
return n;
}