1

In my windows form application which has more than 12 forms and application is for employee attendance module in which every employee log in through his/her username and system mark attendance on logging in.

Now system should mark absent those employees who didn't make his/her login today so i need to generate or execute query at 11:00 PM to do this job but i don't know on what event and where i should call this query to execute at specific time.

I am using c#. thanks in advance.

leppie
  • 115,091
  • 17
  • 196
  • 297
Waqas
  • 847
  • 4
  • 14
  • 36
  • Is your application running 24/24 or only when user(s) launch it ? – Graffito Jul 16 '15 at 11:30
  • possible duplicate of [how to schedule a job for sql query to run daily?](http://stackoverflow.com/questions/5471080/how-to-schedule-a-job-for-sql-query-to-run-daily) – Anant Dabhi Jul 16 '15 at 11:30
  • Perhaps a Windows scheduled task (or a db scheduled task if your database supports them) however if you'll search for "absent" employees but you don't need to perform any _action_ on them then you may not even need any task and present/absent will be resolved at the time you search for them. – Adriano Repetti Jul 16 '15 at 11:31
  • @Graffito, application will run 24/24 – Waqas Jul 16 '15 at 11:32
  • IMO if app is 24/24 has little meaning, it may be crashed, computer may be off, there may be a black-out...it's not something you should handle from inside your app. **If an action has to be performed** then do it using a reliable system (unless you also want to add that complexity to your app). If **no action** has to be performed then you don't need to do anything. **When you need that information** you'll check if employee XYZ was present at day N. – Adriano Repetti Jul 16 '15 at 11:33
  • @AnantDabhi, I read link that you mentioned but if i do this then confirm me either it will run automatically or not? – Waqas Jul 16 '15 at 11:36
  • yes if your sql server running 24*7 so sql then it will run as per ur scheduled time ... – Anant Dabhi Jul 16 '15 at 11:39
  • @AnantDabhi SQL running you means its services running at back end? – Waqas Jul 16 '15 at 11:40

4 Answers4

2

You may develop an application that just generates and executes the query, and then schedule it using Windows Task Scheduler

The Task Scheduler enables you to automatically perform routine tasks on a chosen computer. The Task Scheduler does this by monitoring whatever criteria you choose to initiate the tasks (referred to as triggers) and then executing the tasks when the criteria is met.

The criteria this quote mentions may be a specific hour on the system. In your case, that would be 11 PM.

You can also schedule the process to run on a daily basis, making it to execute at 11 PM every day.

Matias Cicero
  • 25,439
  • 13
  • 82
  • 154
  • is don't want to use windows task scheduler i want to implement it in my code. is it possible? – Waqas Jul 16 '15 at 11:35
  • 1
    You can develop a [Windows Service](https://en.wikipedia.org/wiki/Windows_service) running 24/7, and make it check the time (`DateTime.Now.Hour`) every second. When `Hour` returns `23`, you'll know it's 11 PM and you would run what you need to run. – Matias Cicero Jul 16 '15 at 11:41
  • but on which event if i use timer then where to call its tick event? – Waqas Jul 16 '15 at 11:43
  • I don't recommend using `Timer` for your problem. `Timer` uses an interval to operate, which is not an exact hour. What if your application restarts itself? The interval would be messed up next time the application starts. Also, the interval and the system's clock may not be always synchronized. – Matias Cicero Jul 16 '15 at 11:47
  • I understand what you mean. I will implement it through Windows Task Scheduler . thanks for your precious time. – Waqas Jul 16 '15 at 11:49
  • You can use a timer with an interval of one minute and test if it's past 11h and you didn't already update attendance for the current day. – Graffito Jul 16 '15 at 11:51
0

Use a Scheduling Framework for .NET Platform

You can try Quartz from Nuget or any other similar framework.

Here is an example.

Panayotis
  • 1,743
  • 1
  • 17
  • 30
0

Well you could communicate with the Windows Service to tell it the event via WCF

0

I don't want to use windows task scheduler i want to implement it in my code. is it possible?

You can use a third-party scheduler library. Quartz.NET is pretty good.

I have built a fully operational scheduler in .NET using this library, and although the usage is not trivial I am very happy with its robustness and flexibility.

Xavier Peña
  • 7,399
  • 9
  • 57
  • 99