Customizing clipboard content using background task [Windows 10] [UWP]

I am working on a universal Windows 10 application. At the moment I have a background task that starts after the user receives a notification. The purpose of this BG task is to copy the contents of the notification. The problem is that the Clipboard.setcontent method looks like a single-threaded rather than a multi-threaded BG task. I tried using the corewindow manager, but it didn’t work, I also tried using tasks. Can someone point me to a solution?

eg. The following code in a background task throws an Activating a single-threaded class from MTA is not supported (Exception from HRESULT: 0x8000001D) .

 var dataPackage = new DataPackage { RequestedOperation = DataPackageOperation.Copy }; dataPackage.SetText("Hello World!"); Clipboard.SetContent(dataPackage); 
+4
source share
1 answer

Save the contents somewhere and assign a line to the clipboard until the application is about to resume.

[Update to use dispatcher]

  await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var dataPackage = new DataPackage { RequestedOperation = DataPackageOperation.Copy }; dataPackage.SetText("Hello World!"); Clipboard.SetContent(dataPackage); getText(); }); private async void getText() { string t = await Clipboard.GetContent().GetTextAsync(); } 
+3
source

All Articles