什么会导致等待游标在它应该恢复到默认值之前恢复到默认值?

What could cause a wait cursor to revert to default before it should?

在 Winforms 应用程序中,我将 Cursor 设置为 WaitCursor,然后在 finally 块中将其设置回 Default:

private void buttonGenRpts_Click(object sender, EventArgs args)
{
    try
    {
        Cursor = Cursors.WaitCursor;
        buttonGenRpts.Enabled = false;
        GenerateReports();
        ... // code elided for brevity (and hopefully not levity)
    }
    finally
    {
        Cursor = Cursors.Default;
        buttonGenRpts.Enabled = true;
    }
}

在大多数情况下,它工作正常,但不是全部 - 光标由于某种原因停止沙漏。然而 Cursor 没有在代码的其他任何地方设置(设置为 Default 或其他任何设置)- 仅在上面的代码中。

还有什么可能导致 Cursor 开始诅咒它无休止的振动并停止它的移动吗?

要为整个应用程序设置当前光标,您应该使用

Cursor.Current = Cursors.WaitCursor;
...
Cursor.Current = Cursors.Default;

相反,您的代码设置了当前表单的光标 属性。
可能您将鼠标移到表单边界之外,它会恢复为默认值。

From MSDN Cursor class

All controls that derive from the Control class have a Cursor property. To change the cursor displayed by the mouse pointer when it is within the bounds of the control, assign a Cursor to the Cursor property of the control. Alternatively, you can display cursors at the application level by assigning a Cursor to the Current property