错误:无法使用c#注册热键

Anu*_*uya 7 c#

我使用以下代码使用c#注册热键.但有时我会抛出"无法注册热键"的异常.这个错误的原因是什么?而且不一致.我怎么处理这个?

     public void RegisterHotKey(ModifierKeys modifier, Keys key)
    {
            // increment the counter.
            _currentId = _currentId + 1;

            // register the hot key.
            if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
                throw new InvalidOperationException("Couldn’t register the hot key.");
    }
Run Code Online (Sandbox Code Playgroud)

Ral*_*ine 5

阅读RegisterHotKey的MSDN描述我遇到了:

如果为热键指定的击键已被另一个热键注册,则RegisterHotKey失败.

参考