Pogo
Pogo
CC#
Created by Pogo on 1/18/2024 in #help
EventHandler not triggering.
in Program.cs
namespace ClipboardHistoryCLI
{
internal class Program
{
static void Main(string[] args)
{
ClipboardHandler handler = new ClipboardHandler();

CommandParser parser = new CommandParser(args);
string[] list;

list = parser.ListComponents();
Console.WriteLine($"{list} TEST");

do
{
Console.WriteLine("HI");
Thread.Sleep(1000);
}
while (true);
}
}
}
namespace ClipboardHistoryCLI
{
internal class Program
{
static void Main(string[] args)
{
ClipboardHandler handler = new ClipboardHandler();

CommandParser parser = new CommandParser(args);
string[] list;

list = parser.ListComponents();
Console.WriteLine($"{list} TEST");

do
{
Console.WriteLine("HI");
Thread.Sleep(1000);
}
while (true);
}
}
}
in ClipboardHandler.cs:
namespace ClipboardHistoryCLI._Clipboard
{
internal class ClipboardHandler
{
private Dictionary<string, DataPackageView> _clipboardHistory = [];

public ClipboardHandler()
{
Clipboard.ContentChanged += new EventHandler<object>(this.ClipboardChanged);
}

private void ClipboardChanged(object? sender, object e)
{
Console.WriteLine("TEST");
Console.WriteLine($"{sender}, {e}");
Console.WriteLine($"{sender.GetType()}, {e.GetType()}");
}
namespace ClipboardHistoryCLI._Clipboard
{
internal class ClipboardHandler
{
private Dictionary<string, DataPackageView> _clipboardHistory = [];

public ClipboardHandler()
{
Clipboard.ContentChanged += new EventHandler<object>(this.ClipboardChanged);
}

private void ClipboardChanged(object? sender, object e)
{
Console.WriteLine("TEST");
Console.WriteLine($"{sender}, {e}");
Console.WriteLine($"{sender.GetType()}, {e.GetType()}");
}
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
29 replies