Title: Running my UI app (WPF App) inside Worker Service with C# .Net Core
Tags: c#;wpf;.net-core;windows-services
Question: I'm new in programming with .Net and C# and, as said in the title, I have a WPF app which is accessible in a system tray icon and I want to run it a windows service.
Typically, I want an output like it was described in an answer provided in a discussion here.
```
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 &quot;WPF toast popup&quot; you'll get lots of results.
```
I have many searched in Internet and find some helpful answers like:
URL1
```
You can't, not directly, because the windows service will necessarily start when the machine does, not when a user logs in. The service will also be running in a different context, likely as a different user. What you can do is to write a separate system tray based &quot;controller&quot; that interacts with the service.
```
URL2
```
It needs some effort to achieve. Well, just two hints: 1) use static property System.Environment.UserInteractive to detect in which mode your application is running, see http://msdn.microsoft.com/en-us/library/system.environment.userinteractive.aspx; 2) get rid of app.xaml, because it will force starting WPF Application in all cases; instead, create and run and instance of System.Windows.Application (or better, a specially derived class) explicitly and only for interactive mode, see http://msdn.microsoft.com/en-us/library/system.windows.application.aspx.
```
And, I could not apply their instructions.
Thanks advance!

Comment: https://www.c-sharpcorner.com/UploadFile/naresh.avari/develop-and-install-a-windows-service-in-C-Sharp/  This may be helpful but you should clarify your question.

Comment: I was actually trying to solve this same problem today. I found 2-3 ways of solving this and creating a Windows service seemed to be the most complicated. In case you are open to other ideas, take a look at [hardcodet.net](http://www.hardcodet.net/wpf-notifyicon), which takes the Windows Forms native ability to run an app as a tray icon and ports it to WPF.

Comment: You need to create a Windows service and a Windows application (Win32, WPF, WinForms) which has a notification icon and let them interact by Named pipe or other inter process communication method. You need to learn all of them. BTW, if you just want a Windows application with a notification icon, you don't need a Windows service.

Comment: Thanks @JackArnold. 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.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:05/06/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><wpf><.net-core><windows-services>', 'Title': 'Running my UI app (WPF App) inside Worker Service with C# .Net Core', 'ViewCount': 487, 'id': 67422028, 'user_AboutMe': '', 'user_AccountId': 20806487.0, 'user_DisplayName': 'Ay2S', 'user_Reputation': 13.0, 'user_Views': 11.0, 'user_id': 15281280.0}}