我有来自遗留系统的简单调用,我非常简单的 .NET win 应用程序调用
Clipboard.SetText("small data portion")
此呼叫持续 5 秒。下一个 SetText 调用工作正常。
最重要的(恕我直言)一段调用者代码(VB6):
SAAttr.nLength = Len(MySAAttr)
SAAttr.bInheritHandle = 1
SAAttr.lpSecurityDescriptor = 0
CreatePipe StdOutR, StdOutW, SAAttr, 0&
SetHandleInformation StdOutR, HANDLE_FLAG_INHERIT, 0&
CreatePipe StdInR, StdInW, SAAttr, 0&
SetHandleInformation StdInW, HANDLE_FLAG_INHERIT, 0&
start.cb = Len(start)
start.hStdOutput = StdOutW
start.hStdError = StdOutW
start.hStdInput = StdInR
start.dwFlags = STARTF_USESTDHANDLES
ret = CreateProcess(0&, cmdline, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS + _
CREATE_NO_WINDOW, 0&, 0&, start, proc)
ret = WaitForSingleObject(proc.hProcess, pTimeout)
CloseHandle StdOutW
2个问题:
剪贴板延迟的原因是什么?
如何解决它(但必须阻止调用进程 - 来自非阻塞调用的调用工作正常)?
示例代码:
Dim start1 As DateTime = Now
Clipboard.SetText("simple data")
Dim start2 As DateTime = Now
Clipboard.SetText("simple data")
Dim start3 As DateTime = Now
Clipboard.SetText("simple data")
MessageBox.Show( (start2 - start1).ToString() & vbCrLf & _
(start3 - start2).ToString() & vbCrLf & _
(Now - start3).ToString() & vbCrLf )
结果:
00:00:05.0130000
00:00:00
00:00:00