问题
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