是否有一種簡單的方法可以讓表單上的元素在我單擊 Windows Show Desktop 后繼續更新?以下代碼更新 textBox1 中的值,直到我單擊 Windows Show Desktop(Windows 10 - 單擊螢屏右下角)。我寧愿不使用Application.DoEvents().
void Button1Click(object sender, EventArgs e)
{
int n = 0;
while(true) {
textBox1.Text = n .ToString();
textBox1.Refresh();
Update();
// Application.DoEvents();
Thread.Sleep(200);
}
}
uj5u.com熱心網友回復:
使用Thread.Sleep阻塞當前執行緒(UI 執行緒);你可以像這樣修復它:
private async void button1_Click(object sender, EventArgs e)
{
int n = 0;
while (true)
{
textBox1.Text = n .ToString();
await Task.Delay(200);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/393513.html
