views:

113

answers:

3

Hi !

I've written a console app that sends MS Reports to emails.. (the reason was that i could check it easily if it works) I want this to run daily at 6 am.

My idea was to write a service (so nooone will need to be logged in and the service will run). So I'd like to call the static Method directly in a WebService.

I've a solution with 1 project file that is my console application (with settings, many references.. etc). I'd like to add another project - Windows Service. My question is.. how to do that easily, so I wouldn't have to copy all classes etc to the Windows Service project?

Or am I totaly off the way? :)

Thank you!

A: 

Create a class library and put the shared classes in that library.

Aequitarum Custos
+9  A: 

Sounds like overkill to use a Windows Service to send an email once a day. Why not just schedule a task in Task Scheduler?

duckworth
Will the Task Scheduler run before anyone logs in? or in Background? How exactly does it work? Thanks
PaN1C_Showt1Me
Yes, it runs under the service "Task Scheduler"
duckworth
You only need to provide the proper authentication settings, and the task will run.
Cheeso
The task scheduler can run a job with no user logged in, as long as the machine is booted up. The native windows task scheduler will not do task recovery its just a straightforward "run X at time Y" scheduler
GrayWizardx
And you don't need a new project to do it. You can just run your console EXE under schtasks. simple.
Cheeso
And what about the fact, that the console app shows the console window (with window services the code cannot have GUI). What about Task Scheduler?
PaN1C_Showt1Me
If you schedule it under a different user account (which you should do anyway) it shouldn't show a console window.
duckworth
+1  A: 

You're going to have to refactor your app. I'd recommend three projects -

Console App - instantiates and performs any neccessary set up on your business logic object then routes all output to the console. Use this for debugging and testing

Business logic - Extract all the logic of your application into this class.

Service - Basically the same as the console app except that I would recommend sending any errors to the global event logger. That way if your service bombs you can find out why.

You can use this pattern for any other services you develop.

Ragepotato