更新时间:2023-10-28 21:14:10
问题是您使用 Sleep
调用阻塞了线程.如果您想引入延迟,请查看 Task.Delay
方法.您需要了解一些 async
方法(MSDN 上有大量示例,或者您可以搜索 SO).
The issue is that you are blocking the thread with the Sleep
call. If you want to introduce a delay, look into the Task.Delay
method. You will need to learn a little bit about async
methods (plenty of examples on MSDN or you can search SO).
很可能你需要在 await
延迟时禁用你的 UI,因为延迟允许 UI 继续更新(并显示你想要的颜色变化)但它也允许用户与 UI 交互(例如,再次单击按钮,或单击不同的按钮).Enabled
属性在这里会有所帮助.
Most likely you will need to disable your UI while await
ing the delay, since the delay allows the UI to continue to update (and show the color change you desire) but it also allows the user to interact with the UI (eg, to click the button a second time, or click a different button). The Enabled
property will help here.