开发者

How do I have my WPF application to be running as a service in C#?

开发者_如何学编程I have a WPF application and I want to have it run as a service how do i do it in C#?


EDIT (Based on comment)

If you want to make the program run at startup the easiest would be to change the setup to create a shortcut of the application output (exe) in the below directories:

WIN 7: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
XP: C:\Documents and Settings\All Users\Start Menu\Programs\Startup

Original explanation

Well given that a WPF application is a UI based application and a windows service is not, you would have to take out all of the interaction with the user from the application and then basically recreate it as a service.

There is no easy 1 step process to do this given that they are made to do 2 completely different things.

A service sits in the background and performs tasks that do not recuire user intput, and in most cases does not interact with the user except for a config file; Even though you can run the service to interact with the desktop but that works completely different from a normal wpf program.

A Wpf program on the under hand (as the presentation part of the name suggests) is made to interact with the user.

Why would you want to run it as a service? The whole point of a service is to run in the background with minimum user interaction.


Divide your app into two parts;

  1. A Windows service app that runs in the background (possibly auto runs at dtartup.and runs on system account).

  2. A user interaction app that communicates with.and controls the windows service.

Consider WCF to communicate between the two.

Read about SOA (Service Oriented Architecture) if you want to better understand this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜