I have a WinUI application where I can select the serial port I need for my tasks, from which data will be read in the future. The problem is that I need to do the polling in the background, regardless of whether the interface is open or not. The polling is carried out in a cycle until it is stopped via the tray. That is, when the application is launched, or when a button is pressed, a background process should be launched in which the polling will take place, and which will continue the polling even when the application window is closed. As far as I know, PowerToys is also made on WinUI, and there, pressing key combinations to open the interface is somehow processed, I wonder how this is implemented
I tried:
1) starting threads, but they stop when the window is closed, and the polling stopped.
2) starting the windows service to do the polling in it, but the service refuses to start, just when calling ServiceBase.Run() nothing happens (maybe I did something wrong).
Maybe there is a way to hide the window without ending the program process, and open it back when necessary? or are there any other ways to solve the problem. I will be glad to any advice