0

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 "WPF toast popup" 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 "controller" 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!

Ay2S
  • 13
  • 3
  • 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. – Jack Arnold May 06 '21 at 16:18
  • 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. – Ay2S May 06 '21 at 16:29
  • 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. – emoacht May 06 '21 at 19:49
  • 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. – CyanCoding May 06 '21 at 22:01

0 Answers0