1

I’m working on a windows app composed of two parts:
An agent, running in the background.
A main application with a window to start/stop the agent and configure it.

What I understand is that I should use a “windows service” for the agent.
But I’m not sure how this is supposed to be packaged? (Can I have these two parts in the same .exe?)
And how the agent and the main application can communicate (should I use a shared file? Can my agent have a private folder to work in?)

I’m looking for some architecture advices basically

Simon Watiau
  • 637
  • 5
  • 17

2 Answers2

3

Running the agent as a service is probably the best way to go. It'll run without anyone needing to be logged in to run it, and Windows provides extensive monitoring support for services. You can use the sc command to install, start and stop a service, and it even supports controlling services on other machines if you've got the appropriate permissions.

In order to have your gui communicate with it you could look at using WCF. It will allow you to define your interactions with the service as C# classes and will save you having to worry about checking shared directories or looking into a shared file etc. This approach will also make it easy to support multiple clients at the same time, whilst something like a shared folder approach will make this difficult.

Community
  • 1
  • 1
Sean
  • 60,939
  • 11
  • 97
  • 136
1

You will need to have to separate .exe files, one for the service and one for the windows application. You can package these are two separate MSIs within Visual Studio, the benefit here is that if you need to move the service (for whatever reason) you are not then also packaging up the Windows App and leaving it where ever you install the service.

There are different ways you can have them communicate without getting massively complex. you could read from a text file, as you've suggested, but this could cause locking problems. When I've had to do similar I created a simple database in SQL (or any brand of database you wish), and have the Windows App insert / update configuration options to a table, and the service then reads the table to get its settings.

MattR
  • 641
  • 3
  • 17
  • 38
  • Thanks MattR. However how do you distribute this app if its split in two files ? (they can't be run separately) – Simon Watiau Feb 19 '14 at 09:30
  • You can deploy two exe in one setup/MSI – Milan Raval Feb 19 '14 at 09:34
  • @SimonWatiau You can install them separately or as Milan Raval has mentioned you can deploy both from a single MSI if necessary (but as I said then you're always installing the Windows App even if you don't need it). The benefit of using SQL would be that you can have the app and the service on different machines. – MattR Feb 19 '14 at 10:35