得到蜱虫有什么问题? [英] What's wrong with getting ticks?

查看:83
本文介绍了得到蜱虫有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我获取时间刻度的代码片段。



Below is a snippet of my codes for getting time ticks.

DateTime now = DateTime.Now;
// A double-click is detected if the the time elapsed
// since the last click is within DoubleClickTime.
string lines = "" + (now.Ticks - previousClick.Ticks);
System.IO.StreamWriter file = new System.IO.StreamWriter(@"e:\tmp0\test.txt", true);
file.WriteLine(lines);
file.Close();
if ((now.Ticks - previousClick.Ticks) <= 10000 * (SystemInformation.DoubleClickTime))
{
    // Raise the DoubleClick event.
    if (DoubleClick != null)
    {
        //MessageBox.Show("raise double click");
        DoubleClick(this, EventArgs.Empty);
    }
}
// Set previousClick to now so that
// subsequent double-clicks can be detected.
previousClick = now;





这段代码每次点击都会执行一次。无论我点击多快,我在两次点击之间得到了很大的差异,如下所示。它出什么问题了?在我看来,我希望每个差异最多只有1000左右,因为它的单位是毫秒。





635581521847201967
31031775

16800961

16720956

18001030



This section of codes are executed once for my each clicking. No matter how quick I click, I got very big tick difference between two clicks, as below. What's wrong with it? In my mind, I expect each difference should be just 1000 or so at most because its unit it milisecond.


635581521847201967
31031775
16800961
16720956
18001030

推荐答案

请参阅 https://msdn.microsoft.com/en- us / library / system.datetime.ticks(v = vs.110).aspx [ ^ ]。


我自己试了一下

是的,我得到相同的结果:无论我输入多快都有限制。

这可能是因为操作系统有许多进程并在任务之间切换。

否则我们的电脑无法进行多任务处理。



I just tried it myself
Yes, I get same result: no matter how fast I type there is a limit.
This is probably due to the fact the OS has many processes and switches between tasks.
Otherwise we could not have multi-tasking on our computers.

static void Main(string[] args)
        {
            Console.WriteLine("DoubleClickTime = " + SystemInformation.DoubleClickTime.ToString());
            long ticks = 0;
            DateTime previous = DateTime.Now;
            char c = (char)0;
            while((c=Console.ReadKey().KeyChar)!='q')
            {
                DateTime now = DateTime.Now;
                ticks = now.Ticks - previous.Ticks;
                Console.WriteLine(": Ticks= {0}", ticks);
                previous = now;
            }
            Console.ReadKey();
        }


这篇关于得到蜱虫有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆