Skip to content

Commit 612fb36

Browse files
committed
Thread safety of image copying
1 parent 0d1ff89 commit 612fb36

File tree

1 file changed

+3
-4
lines changed
  • QuickLook.Plugin/QuickLook.Plugin.ImageViewer/NativeMethods

1 file changed

+3
-4
lines changed

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/NativeMethods/ClipboardEx.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ public static void SetClipboardImage(this BitmapSource img)
2121
var thread = new Thread((img) =>
2222
{
2323
if (img == null)
24-
{
2524
return;
26-
}
2725

2826
var image = (BitmapSource)img;
2927

@@ -36,15 +34,16 @@ public static void SetClipboardImage(this BitmapSource img)
3634
try
3735
{
3836
using var pngMemStream = new MemoryStream();
39-
using var bitmpa = image.ToBitmap();
37+
using var bitmpa = image.Dispatcher?.Invoke(() => image.ToBitmap()) ?? image.ToBitmap();
4038
var data = new DataObject();
4139

4240
bitmpa.Save(pngMemStream, ImageFormat.Png);
4341
data.SetData("PNG", pngMemStream, false);
4442

4543
Clipboard.SetDataObject(data, true);
4644
}
47-
catch { }
45+
catch { } // Clipboard competition leading to failure is common
46+
// There is currently no UI notification of success or failure
4847
});
4948
thread.SetApartmentState(ApartmentState.STA);
5049
thread.Start(img);

0 commit comments

Comments
 (0)