4

So this is my first stint with programmatically creating windows service or scheduled tasks and I am confused which one to choose. I had a look at various articles like http://weblogs.asp.net/jgalloway/archive/2005/10/24/428303.aspx , scheduled task or windows service and some more but can' t really decide btween the two

Here is my scenario :

My application will pick up the code paths of a few dlls from the db , execute the DLLs using MSTest.exe and log back the results to the Db. this will probably be repeated every 2-3 hours . Now I am leaning a bit towards scheduled tasks since i won't have to worry about memory related issues but need some expert advice on this.

P.S. : The DLLs contain test methods that make calls to web services of applications deployed on various servers

Thanks in advance for the help

Community
  • 1
  • 1
blank
  • 109
  • 1
  • 3
  • 12
  • 1
    "...since I won't have to worry about memory related issues" - If you mean defects in your code like memory leaks, then that is absolutely something you should worry about no matter what solution you choose. Choosing a tecnology because it allows you to be sloppy is a bad idea. – René Feb 09 '16 at 10:01

2 Answers2

14

A Scheduled Task would be more appropiate for your scenario. I don't think it make a lot of sense building a scheduling mechanism on a windows service when OS already provides scheduling infraestructure.

A Windows service is more appropiate for processes that have to respond to events at any moment and not at specific and fix periods. That's why they are running all the time. An example of this is the SQL Server Service.

An exception of this could be a task that needs to run every second or so. In that corner case, a Window Service could be the best solution. For your specific schedule, I have no doubts that a scheduled task would fit much more better.

Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
  • thanks Claudio , thats exactly what I am thinking . I am not sure about the permissions it needs to run though . As per my understanding , for creating a task i need admin privileges and what about running the task? Also since the n/w account will have access to the db and web services , will the tasks run properly under the network account? What if i change the password? Just trying to cover my tracks here.... – blank May 21 '13 at 19:30
  • @nikhil: It's not mandatory to run with admin privileges but it may require an account with more permissions depending your scenario. For accessing db and web services default credentials should be enough under normal circunstances. – Claudio Redi May 21 '13 at 19:34
  • @CLAUDIO..what about running the task when the user is not logged on? I read that it stores the user's password to achieve this functionality. Will this be feasible programmatically ? also what about handling multiple instances? for ex a task may take more time than expected and might coincide with its rerun time...does scheduler have any feature to handle this? – blank May 21 '13 at 20:16
  • @nikhil: when you create the task it will ask you if can run when user is not logged on. Two instances can run at the same time without problems unless you have a requirement to not do so. – Claudio Redi May 21 '13 at 20:37
  • @ CLAUDIO...so i have a small issue now...when i run my task with the option "Run whether the user is logged on or not" , some of my test methods(more specifically the UI tests) do not work . It is because windows does not allow the task to be interactive. Any fixes around this issue? – blank May 23 '13 at 20:13
  • @nikhil: off topic question: why you're tryng to run tests? Is that part of the task resposabilities? – Claudio Redi May 23 '13 at 21:29
  • Yes , I am trying to create a console application which runs MSTest.exe from my c# code and then schedule a task to run the console application – blank May 23 '13 at 22:02
0

Although this post is several months old, here's a possible resolution in case it's helpful to others for the "Run whether the user is logged on or not" issue : start with a console project then change type to Windows App as mentioned at Run code once and exit formless app: Windows Forms or WPF... does it matter?: “If you never show a UI, you should start with a WinForms project (WPF projects set extra project metadata that you don't want), then delete the reference to System.Windows.Forms.dll. Alternatively, start with a console project, then change the Output type to Windows Application.”

Community
  • 1
  • 1
sttalents
  • 1
  • 2