未处理的异常:System.ComponentModel.Win32Exception:操作成功完成

时间:2014-10-02 04:05:00

标签: c# visual-studio-2013

每当我尝试运行此代码时:(代码缩短以保持帖子简短)

// Generate a random capital letter
char key = (char)(_random.Next(24) + 65);

// 50% make it lowercase
if (_random.Next(2) == 0)
{
    key = Char.ToLower(key);
}

SendKeys.SendWait(key.ToString());

我收到此错误:

Unhandled Exception: System.ComponentModel.Win32Exception: The operation completed successfully
  at System.Windows.Forms.SendKeys.SendInput(Byte[] oldKeyboardState, Queue previousEvents)
  at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
  at System.Windows.Forms.SendKeys.SendWait(String keys)
  at DrunkPC.Program.DrunkKeyboardThread() in c:\Users\SPC\Documents\Visual Studio 2013\Projects\DrunkPC\Program.cs:line 91
  at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  at System.Threading.ThreadHelper.ThreadStart()

第91行是:

SendKeys.SendWait(key.toString());

0 个答案:

没有答案