I use the following C# code, to get an event, if a device is attached to a COM port.
WqlEventQuery query = new WqlEventQuery("__InstanceCreationEvent", new TimeSpan(0, 0, 3), @"TargetInstance ISA 'Win32_SerialPort'");
var watcher = new ManagementEventWatcher(query);
watcher.EventArrived += EventArrived;
watcher.Start();
This code works also on all PCs. But on many PCs with Windows 11, the event EventArrived is not raised if I attach a device to a COM port.
Any idea what I have to change?