Question

I have simple call from legacy system, my very simple .NET win application calls

Clipboard.SetText("small data portion") 

This call last 5 seconds. Next SetText calls works fine.

Most important (IMHO) piece of caller code (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 questions:

  • What is the reason of clipboard delay?

  • How to fix it (but calling process must be blocked - call from non blocking calls works fine)?

example code:

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 )

Results:

00:00:05.0130000

00:00:00

00:00:00

Was it helpful?

Solution

I had the same problem for years with VB6 when using the clipboard to transfer data to Excel when Ouutlook and/or Word was running.

The problem is with Office; you need to disable the copy multiple item to/from clipboard to speed it up.

https://support.microsoft.com/en-ca/help/2817672/macro-takes-longer-than-expected-to-execute-many-individual-copy-and-p

Hope this help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top