I am developing a specific application that needs to execute a task "n" number of times per day with a set maximum.. But without a set time. Can this be done? What is the preferred method of doing so?? in vb.net or C#.net
It's hard for me to imagine what kind of task you would want to run a maximum number of times without being linked in anyway to a timer. Is a user or some other process going to make the task execute and you don't want them to be able to execute it more than 'n' times?
A little more information would help clarify because it isn't clear to me what you are trying to accomplish.
My guess is going to be one of the following will accomplish what you need:
1)Create the application and install it on a server. Create a windows scheduled task to call the application on a schedule such that it does not exceed your maximum run count per day(i.e. every 4 hours)
2)Similar to #1, I also use SQL jobs to call tasks on schedule and keep track of success/failure and alert me to such.
3)Create the application as a service and install it on a server such that it is running all the time. Include a timer in the application such that the desired event is called when the timer fires. You could either make the timer fire on the schedule desired or keep track of how many times it has ran during the current date using variables. Then exit the timer event without calling the task code if it has already ran the maximum number of times that day. Of course, using this method if you restart the service your variables would be lost so you would be better off storing the number of times ran today outside of the application(database, file, etc.)
4)If the task is being called from another process which seems most likely from what you've stated, I would create a table in a database that minimally contains a date and integer field. Each time the task was executed, I would update the integer field. If the maximum has been reached for the date, I would abort the process and inform the user or calling process. If you don't have a database available, you could store this same data into and read it from a file.
Post more info if this doesn't give you some guidance in how to proceed.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.