❔ Background process in tray without window
I'm having a hard time finding information on running an app in the system tray without a window. In this case it's a little console app that will make an API request every 2-3 hours to automate something.
Everything I've found so far either refers to ASP.NET, UI background workers or using a process to start another process without a window using the Process class.
If there really is no other way to do it other than using the Process class to start another process of my own without a window, how would I publish it to have both processes and have the starting process correctly reference the background process?
5 Replies
Look at creating it as a Windows Service instead, you can use the BackgroundService for this
Create Windows Service using BackgroundService - .NET
Learn how to create a Windows Service using the BackgroundService in .NET.
as for the tray I am unsure of why you need the tray if you just need it to run an API request every 2-3 hours
otherwise you can setup an Application which includes a NotifyIcon which can reside in the tray
Some of the extension methods used in their Rewrite the Program class example aren't available in their most recent .NET 7 version 7.0.1, like AddWindowsService for the host builder
Which I hopefully assume would be the same as a hosted service's AddHostedService
But this is what I needed, thanks
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.