dotnet / dotnet/wpf

Extremely slow clipboard operation when some clipboard monitor application running

Open
#9,106 1 comment 4 reactions 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

When running software that includes clipboard monitoring features, all WPF applications on the computer may become extremely slow when performing clipboard copy operations. Meanwhile, other programs such as Winform applications, browsers, and Windows Notepad operate normally.
Symptoms: When selecting "Copy" (or "Cut") from the right-click menu in any text box, it takes 0.5 to 1 second for the menu to close.

https://github.com/dotnet/wpf/assets/1972649/8b74c764-2aa2-4d9a-ad00-30c9571fd256

Compared to winform application:

https://github.com/dotnet/wpf/assets/1972649/602add4b-9f90-490d-8fa5-c7597793ea73

### Reproduction Steps

[TestClipboard.zip](https://github.com/dotnet/wpf/files/15315438/TestClipboard.zip)

1. Download and unzip the above TestClipboard.zip file, and unzip to a folder.
2. Sample application was based on .Net8, you should have .Net8 installed on your computer.
3. Start the applications in the following order. (Order is important) **1)** WpfApp1.exe **2)** ClipobardMonitor.exe **3)** InsideClipboard.exe

![image](https://github.com/dotnet/wpf/assets/1972649/bc333696-9c08-4b37-ab2f-75d8eaa31195)

4. Select some text in WpfApp1.exe window, right click, then select COPY menu. it will close with big delay.

https://github.com/dotnet/wpf/assets/1972649/ad11f4b4-9542-4641-80b4-27f7e657e871

### Expected behavior

Copy operation should complete immediately.

### Actual behavior

Copy will complete with big delay and UI freeze.

### Regression?

This problem exists for a long time, both .NET framework and .Net8.

### Known Workarounds

No workgorund.

### Impact

Very bad user experience.

### Configuration

_No response_

### Other information

Time was costed in System.Windows.Clipboard.CriticalSetDataObject, It fails to olesetclipboard and retry many times with Sleep().

0d5a2326547d4ed4f458a69531d2a057

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.