I'm new to windows services. I want to make a windows service which work as an execution engine for my software. Currently I am passing a XAML file path to my execution engine to start execution. Now i wanted to create a windows service to act as an execution engine. Is there any way to invoke my Run method with File path (as an argument) in a running service?
-
XAML implies a GUI, no? Services run in their own separate desktop sessions, where you can't see the GUIs of whatever applications they choose to start. Services are not intended for anything that requires user interaction. If you want an interactive launcher of some sort, run it from the shell Startup. – Jeroen Mostert Aug 25 '17 at 17:05
-
My gui will generate the xaml file on pressing run button and i am passing this file to execution engine for further process. i wanted to separate my execution engine( as a windows service) and UI. Run button will call the Run method in windows service for further execution. is there any way to achive this or there is any other way to do that. – Syed Arham Aug 25 '17 at 17:14
-
So you want your service to start your application when the application is started? Services are not meant to interact with any user related stuff. – Snicker Aug 25 '17 at 17:15
-
@SyedArham if you want to build up a communication channel between your service and desktop application, you can use named pipes (easiest would be using WCF on top of that). – Snicker Aug 25 '17 at 17:15
-
You can [ask your service to do things](https://stackoverflow.com/q/1773046/4137916), as long as you keep in mind that it cannot display anything. – Jeroen Mostert Aug 25 '17 at 17:16
-
@Snicker I will read about WCF. – Syed Arham Aug 25 '17 at 17:19
1 Answers
As others have mentioned, the best way to do this is probably by using a framework that supports some form of communication mechanism. Again as others have already mentioned WCF is great for this.
As an initial pass what I would do would is to use a self-hosted WCF service (this Code Project entry provides an example on how to do this: https://www.codeproject.com/Articles/650869/Creating-a-Self-Hosted-WCF-Service). The overhead is that you will have to learn WCF basics to get this going, although WCF is very easy to get started with.
In this context what self-hosted WCF Service means is that you are creating the hosting code yourself, instead of hosting in another service/location. For example, you can also host a WCF Service in IIS.
In the example the author is creating a SvcHost
object and running it in a console application. The console application is user interactive, however, this should be easily translated to a Windows Service.
Hope this helps.

- 16
- 2