New Thread.Sleep behaviour under Windows 10 October Update 20H2

大憨熊 提交于 2021-02-08 10:22:58

问题


So I have thrown together a quick repro to highlight the issue while helping myself to understand what on earth was going on in my main app, after receiving many user reports of sudden slow behaviour out of nowhere after more than a year without issue. An active user of my application pointed out that the problem only came about after a recent Windows update, it led me to verify that it was indeed caused by the October Update 20H2.

using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

namespace SleepRepro
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void startButton_Click(object sender, EventArgs e)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            new Thread(() =>
            {
                Thread.Sleep(5);
                Log("Sleep took " + sw.ElapsedMilliseconds + "ms");
            }).Start();
        }

        public void Log(string str)
        {
            Invoke((MethodInvoker)delegate
            {
                logTextBox.Text += str + Environment.NewLine;
                logTextBox.SelectionStart = logTextBox.Text.Length;
                logTextBox.ScrollToCaret();
            });
        }
    }
}

It appears there is a new loss of precision in Thread.Sleep?

I guess my question is whether or not this is intended behaviour or a bug? Is there some documentation of it somewhere?

Thanks in advance.

来源:https://stackoverflow.com/questions/64633336/new-thread-sleep-behaviour-under-windows-10-october-update-20h2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!