0

I need to write an application that run in the background (i.e., invisible to user). It should be always running when the server is on, regardless of user login or off. Or at least it should run on schedule (e.g., hourly). It also should still run after the server shut down and turn on again.

The application is used to backup some data from one server (linux) to the local server where the application run (windows server).

From my research, many suggest to use Window Service. But I'm newbie on C# and also on this area like Window Service.

Can anyone direct me where I should start? Is Window Service a suitable solution? Or if there is better solution? Please explain.

Thank you in advance.

[CLOSED] Thank you for all who has responded.

shinega
  • 113
  • 1
  • 4
  • 13

4 Answers4

1

Yes, the best practice is windows services.

However, if your operations are simple enough to write in DOS batch file. You can schedule your task in windows task scheduler. It will save a lot of time and is easy to setup.

UPDATE (FYI)

I have a batch_update.sql file that needs to be executed at 1.00AM every day. I created batch_update.sql file and a batch file batch_update.bat in C:\bat.

batch_update.sql includes all SQL operations. batch_update.bat calls batch_update.sql file to execute it as follow.

sqlcmd -U adminuser -P password -S (local) -i C:\bat\batch_update.bat -o C:\bat\batch_update.txt

Then I created a task in windows task scheduler to run at 1.00AM which works pretty well.

Jonas T
  • 2,989
  • 4
  • 32
  • 43
  • Sorry, what's DOS batch file? I'm still newbie on this and not familiar with all the terms. Basically I need to copy data from some text file into the database in different server. – shinega Feb 27 '13 at 03:12
  • .bat files. It can be run in command prompt. It is possible to read text file data and import to SQL database in batch file but it will be hard for you if you are not very familiar with this. leehn0058's solution is more suitable for you. – Jonas T Feb 27 '13 at 04:31
  • I see. Indeed, I'm not familiar with this. Anyway, thank you. – shinega Feb 27 '13 at 04:59
0

A windows service definitely sounds like the long term solution. For simplicity however, you could create a command line project in C# and then use windows scheduler to run it in whatever intervals you like.

lehn0058
  • 19,977
  • 15
  • 69
  • 109
  • could you give me link or example on command line in C#? Is it similar like Java using javac kind of thing? – shinega Feb 27 '13 at 03:06
  • It's made by the type of project you create. You can select a command line application in visual studio when you create a new project. Building it will create a .exe file that will run your code. – lehn0058 Feb 27 '13 at 03:09
  • I see. But if i use windows scheduler to run the exe -say, hourly-, when the server shut down and then turn on again, would it still scheduled to run every hour? – shinega Feb 27 '13 at 03:17
  • When you make a schedule through windows scheduler, you can configure it to start running the schedule on start up again. – lehn0058 Feb 27 '13 at 03:25
0

I recommend windows service too, you can have some information right here.

Freddie Fabregas
  • 1,162
  • 1
  • 7
  • 17
0

Yes, Windows Service is the solution you're looking for. Here's a good starting point on MSDN.

Krzysztof Kozielczyk
  • 5,887
  • 37
  • 28