My WPF application checks the data on the clipboard to see if it can work with the data or not. Because I set some buttons to be enabled/disabled based on the data (via an ICommand
implementation), this code is called frequently.
The work to determine if my application can work with the data can be non-trivial at times, and thus is causing my application to "hang" randomly. I don't believe I can push this work off to another thread since the WPF runtime is expecting a response quickly.
In order to solve this issue, I thought I would compare the IDataObject
s (the current one from the clipboard vs. a cached one from the previous attempt. A straight comparison (and even an object.ReferenceEquals
does not return the desired results, so I thought I would try the method Clipboard.IsCurrent
. The description sounds like exactly what I want, but when I evaluate the following:
Clipboard.IsCurrent(Clipboard.GetDataObject())
the result is false
. The current workaround is to compare the data formats on the IDataObject, but that's not a good answer since my application can handle some files from the file system, but not all. So even though the formats are identical, the result on whether my application can handle the data may not always be the same.