当前位置: 首页>>代码示例>>C#>>正文


C# Stopwatch.GetType方法代码示例

本文整理汇总了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;
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:52,代码来源:StopwatchExtensions.cs


注:本文中的Stopwatch.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。