Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL Windows .NET , +
I am a ASP.NET developer and at present I work with C# and SQL Server.
 
I would like to have an automated process which does the following:-
[1] Connect to SQL Server
[2] Select FTP data (host, username and password) and "time to pull data" from a table
[3] Based on the "time to pull data" (say example 6:00am), it should connect to the FTP server using the selected FTP data
[4] Download all the files available in the FTP server to the local system.
[5] And this process should be executed continuously since, the step [2] will select more than one row with different FTP data and it's corresponding "time to pull data".
 
Having said the above requirements, my clarification is:-
[1] Should I use Windows Service or Schedule Task
[2] If "Windows Service" then how can the above requirement will be achieved, that is connecting to database, pulling data, connecting FTP as a said point of time, downloading available data to local system and the process round the clock?
[3] If "Schedule Task" then how can I develop modules task for "Schedule Task" using .Net and integrate that module in "Schedule Task".
 
Your timely guidance with sample code will be highly appreciated.
 
Mohandas K
Posted 18-Apr-11 19:31pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I would choose a scheduled task for its simplicity anytime. In the earlier days I did use windows services. But time and again I have realized that a scheduled task is pretty simple and straight-forward. Thats because, in the case of a windows service, you need take care of whether its startup mode is automatic or manual and if its manual, you have the pain of starting the service, forgetting which could cause you unwanted issues. Of course you could set it to be automatic, such that the service starts when your machine is restarted.
 
But you have the overhead of taking care of when to run the service and so on. On the other hand if it's a scheduled task in windows, you need not worry about the startup modes or the windows service related functionality and just concentrate in the actual task of your application.
 
If you plan to have a scheduled task, you just need to develop a console based application that does what you need. You could also set up the console window to be hidden, so that the console window does not appear when the scheduled time arrives, as it could be annoying to the users (or you) of that system.
 
PS - This is just my opinion, if you like to differ, please add why as a comment as this could be informative for others too. Thanks!
 
Hope this helps!
  Permalink  
Comments
mohask at 19-Apr-11 1:15am
   
@ Karthik -
Thanks for your reply.
As advised by you I can foresee the issues of using a Windows Service.
Can a console application add tasks to the Schedule Task dynamically without human interference? For example, every time when I add a new record in my table with FTP details and time to pull data, can we add this task corresponding to this record on the schedule task without having to execute the console application every time while adding new record?
Karthik. A at 19-Apr-11 1:41am
   
You need not create a scheduled task from the console application. Its the other way around - you create a scheduled task that runs your console application at the specified intervals. It would be the duty of the console app to access the database get the information on what needs to be done and do it. Refer to this link for an example - http://www.iopus.com/guides/winscheduler.htm. A windows scheduled task expects some thing that it could run - it could be anything, say, an executable, batch file, etc etc - with or without parameters.
mohask at 19-Apr-11 2:30am
   
Thanks for the info Karthik. I am looking for that automation process which will trigger another process to download files through given FTP server and a given point of time. There could be several FTP servers which has to accessed only at a given time relevant to that FTP server. In Task Scheduler, the minimum interval between the repeating a task is 5 mins, whereas there could be some FTP servers which would be required to access within that 5 mins of interval. So the "Task Scheduler", will always run the process atleast few mins delayed than the expected time of execution of my required task.
 
Thinking out of the box, rather than depending on Task Scheduler, can we develop an windows application, that can run at the background, hiding itself in the task bar just like another application which run hiding and showing only it icon at the right side of task bar beside time / date (like instant messengers, antivirus, etc.,) ? If yes can you please advise me how can it be done ??
shravaniraj at 25-Jun-13 10:57am
   
Hi Mohandas,
 
I got the same requirement as mentioned above and asked to develop a Windows service. Please let me know, if you got the solution for your question.
 
Thanks for your time and help.
 
-Sri
mhanvelt at 25-Jun-13 16:27pm
   
Spot on. I have written stuff that works exactly this way in the past, and I highly recommend it for unattended batch processing, with a couple of things to be aware of first.
 
1) Scheduled Tasks (in more recent versions of Windows, it's called Task Manager, and it's under Administrative Tools) will not run more often than every 5 minutes. You set it up to trigger the actions daily at a set time, repeating every 5 minutes thereafter. From what I can tell, you cannot run your task trigger more often than this. If you need to run it with more than a 5 minute granularity, you'll have to use a Windows Service and a threading timer.
 
2) Building a new command line app for every task you want to trigger is a difficult-to-maintain mess. So you're going to have some overhead with a general-purpose task engine. The ones I've written are specific enough to require an input, archive, and error directory path (or hostname, paths, and credentials for FTP) for each sub-task. The engine checks the database to see which sub-tasks need to run right now, and it kicks them off. The sub-tasks themselves are smart enough to go get their files from the input location and process them, then move them to the archive or error locations (pass/fail style, and we keep a complete history).
 
So there's a table in the database that tells it when to run, where to get data, where to put data, and what classname to instantiate to process the data. There's a command-line app that gets that config for the currently needed processes, instantiates each active process' class, and runs it. And there's a timer that kicks off the command-line app every 5 minutes.
 
It works well and it's dirt simple. Let the OS handle the timing stuff. Don't invent your own if you don't have to.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

As you are looking to connect to SQL Server to start this process off, I'd actually look to schedule the task inside SQL Server. Have a look here[^] for details on how to create a regularly scheduled task. The beauty of this approach is that you can still do all sorts of clever .NET things inside SQL Server, but you remove the dependencies on other systems.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 386
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 215
3 /\jmot 189
4 Praneet Nadkar 173
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 25 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100