EventHandler not triggering.
in Program.cs
in ClipboardHandler.cs:
Wrote a very basic setup to learn to work with an EventHandler. The event however does not trigger, I had wrapped Main into an async method, I made ClipboardChanged async, i added an async delay on the main keep-alive loop, nothing worked for me. Any idea why the EventHandler doesnt trigger?
ClipboardChanged is an official UWP EventHandler: https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.datatransfer.clipboard.contentchanged?view=winrt-22621
Clipboard.ContentChanged Event (Windows.ApplicationModel.DataTransf...
Occurs when the data stored in the Clipboard changes.
15 Replies
FWIW, the explicit
EventHandler
is outdated, you can just Clipboard.ContentChanged += ClipboardChanged;
have you put a breakpoint in the handler to see if it's really triggering or not?weird that they didnt update their own docs?
how do i add a breakpoint in VS?
click in the left hand gutter, that's how it works in rider anyway
Isn't it the clipboard history API?
yep found it
Press Windows key + V
there's a clipboard HISTORY api and a normal one
clipboard history changed
and regular clipboard content changed
(i want to track when new content entered the current clipboard)
though I dont understand what im doing wrong, is my eventhandler incorrect? is my keep alive loop incorrect?
Never used said API, but this seems interesting
You can only access the clipboard when the calling application is in focus on the UI thread (for example, when its CoreWindow is active). Use the CoreWindow.Activated event to track the state of the calling app.https://learn.microsoft.com/en-us/uwp/api/windows.applicationmodel.datatransfer.clipboard?view=winrt-22621
also no, clipboardchanged did not even trigger
Which may be an API exclusive to UWP applications
well, i use the UWP framework but
As console applications does not have a UI Thread
they explicitly want me to instance a CoreWindow..?
bro why do they do this
they do this with every application ever
how about if i spawn an invisible CoreWindow
no actual window anywhere
it just 'exists'
sounds like a security thing if they want the window to be in focus
yet their own clipboard history app is allowed to
grrr