Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi everyone,
I have a WPF app which is accessible in a system tray icon and I want to run it a windows service.
Typically, If I take an exemple from a popular Apps I would choose Microsoft Teams which starts in a system tray icon at startup Windows, it works permanently in background and if I click in the startup icon it shows the GUI.

What I have tried:

I found an answer here but I could not apply his proposition.
Thanks advance!
Posted
Updated 6-May-21 21:11pm
v2

You cannot run a UI app as a service at all: a service cannot interact with the user in any way, form, or manner - as services can (and do) run before any user is logged in - and until a user is logged in, there is no user to interact with, or user permissions which can be applied.
Services run under a special account which cannot have any display, and cannot start any apps which do have a display.

To make your app work as a service, you would have to create a new Service project and transfer the code you need to that.
 
Share this answer
 
Comments
Ay2S 7-May-21 3:16am    
Hi OriginalGriff,

Thanks, I can see more clearly.
Effectively, your proposal fits well with a suggestion which I found in a discussion at [1], about the architecture of the project must be.
However, I can't see how I would do this: How the windows service project could call the WPF project and run it?

[1]: https://docs.microsoft.com/en-us/answers/questions/18371/minimize-a-wpf-application-to-system-tray-in-c.html

Thanks!
Hi OriginalGriff,

Thanks, I can see more clearly.
Effectively, your proposal fits well with a suggestion which I found in a discussion here[^], about the architecture of the project must be:
Quote:
If you want it in the system tray I think what you'll have to do is make it a Windows service. I've only written 1 Windows Service and that was years ago, but I believe that's what you'll have to do. If I'm correct about writing a Windows service, then what I would suggest you do is create a new Visual Studio solution and add two projects to it. One would be a DLL which would run as a Windows service. The second project would be a WPF project that will be your UI the user interacts with. Then you'll have to use some messaging system to communicate between the two. For the action messages that would mimic what Outlook does, I've used some WPF toast messages to accomplish that. If you Bing/Google "WPF toast popup" you'll get lots of results.

However, I can't see how I would do this.

How the windows service project could call the WPF project and run it?

Thanks!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900