2

I know variations of this topic have already been asked, but here's my situation:

I have about 30 FTP interface applications. Each interface has their own requirements and configuration, but basically it downloads files from a source server – sometimes daily, sometimes every minute (some, possibly even scheduled in the seconds)

For my initial development, I wrote a C# class library that does all FTP work. This application (be it a console app or windows service) will most likely be run under Windows Server 2012.

Now comes the next piece and I’m trying to decide between:

1) Writing a console app (or a powershell script?) that takes command line inputs plus a configuration file for each interface. I would schedule this using Windows Task Scheduler. For deployment of these interfaces, I could create a batch file that uses the “schtasks.exe” to create and configure the task. One task for each interface. Sounds easy peasy…

OR

2) Write a windows services application… but here, I am confused. Do I create and install a service for each one of my interfaces? (i.e. only thing different might be the config file). Or, do I create a a main service that spawns off threads for each interface defined in a single config file?

If I did this as a single service, how do I manage the maintenance/deployment of this? If I stop the service, would it not affect all the interfaces? And how do I perform the actual scheduling? I’ve read the suggestion is to use Quartz.Net scheduler or just .Net Timers.

---

Some additional thoughts: Here are some readings on StackOverflow which brings up these topics/concerns:

windows service vs scheduled task Scheduled console app vs Windows service? When is it appropriate to use each

Task Scheduler Concerns

  • List item
  • May need to be logged in? (I’ve read this is not true)
  • Issues on machine admin password change (I’ve read this is not true)
  • Issues with running in high-authority accounts (NetworkService, LocalSystem, or a User)
  • Issue with multiple processes / long running transactions This would be really bad for me, for example, if two processes tried to download (and delete) the same source FTP file.
  • Experience of many is that this is not as stable/reliable as Windows Services, especially on earlier operating systems pre Windows7
  • Less infrastructure support (e.g. failure policies for retry, monitoring, etc.)
  • Concerns when scheduling in the seconds…

Windows Service Concerns

  • List item
  • Potential issues with Timers
  • More complicated

Console App + Scheduled Task Concerns

  • List item
  • Can’t run in background – so hosting server will have command prompts launching This is a serious problem. If I have 30 FTP Interfaces and each is scheduled to run every minute/hour, that’s a lot of windows!!!
  • How do I get around this? Use PowerShell scripts instead?

Looking forward to some feedback, and sample code/scripts, if relevant also highly appreciated.

Thanks

1
  • full real world sample (C# library for FTP) with good patterns and practices using task scheduler, windows service or quartz ? Dec 1, 2017 at 18:15

1 Answer 1

2

You can access your c# class in powershell using Either add-type or [System.Reflection.Assembly] - check out this SO post for examples - Can I access My Custom .NET Class from PowerShell?

You could do it all in powershell, using start-job and the like, but then your controlling script will need a lot of effort.

I'd be tempted to use Powershell' inbuilt (in version 3) cmdlets for creating/modifying scheduled jobs in task scheduler and custom triggers - http://blogs.technet.com/b/heyscriptingguy/archive/2012/09/18/create-a-powershell-scheduled-job.aspx

Have it schedule jobs that are running .ps1 powershell scripts, one for each transfer or group of related transfers e.g. Monthly_Payroll_xfer.ps1, Weekly_Expenses_xfer.ps1 with logic relevant to that transfer, email alerts on success/failure etc.

The only thing that doesn't solve is same file/destination being processed at the same time but you could potentially have the individual scripts check at start if they are running already - see the accepted answer to this post - Assure only 1 instance of PowerShell Script is Running at any given Time

As for windows prompts, you can run a scheduled task as a user that won't be logged on, and you won't see the powershell command windows as they will be on a different console - be sure not to set -noexit switch of powershell.exe so they do go away when finished.

Had to do this at work for a tool that only runs as GUI, not as a service, and can't be frigged with srvany etc - we setup a scheduled task that runs (at startup) as a service account and runs a powershell script that runs the GUI.exe

We then use powershell scripts to stop-process to kill it, disable/enable the task (like disabling/enabling a service) and one to run the task.

It's a cludge but it works.

Apologies I haven't given much in the way of code examples, doing this on my phone but may give you ideas.

You can also do it all in c# - we have an in-house developed application with SQL back-end that does exactly what you're trying to achieve, very successfully, multi-threaded with very high volumes being chucked at it..

However, my employers' Intellectual Property and other policies prevent me sharing any more about it than that :-(

Not the answer you're looking for? Browse other questions tagged or ask your own question.