gpt4 book ai didi

c# - 应该使用 Application.UseWaitCursor 吗?

转载 作者:行者123 更新时间:2023-11-30 14:00:56 25 4
gpt4 key购买 nike

使用 Application.UseWaitCursor 关闭和打开沙漏鼠标指针有什么危险吗?

最佳答案

“危险”在于不恢复光标。

您可以使用 try...finally block 来确保即使抛出异常也能恢复游标,或者通过将此功能包装在实现 IDisposable 以便您可以使用 using block 。

  public class WaitCursor : IDisposable
{
public WaitCursor()
{
Application.UseWaitCursor = true;
}

public void Dispose()
{
Application.UseWaitCursor = false;
}
}

用法:

  using (new WaitCursor())
{

// do stuff - busy, busy, busy

} // here the cursor will be restored no matter what happened

关于c# - 应该使用 Application.UseWaitCursor 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9494133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com