简体   繁体   中英

How to implement scheduler with Windows Form Application in VB.Net

I am working on Windows application which is developed in VB.NET. This application contains multiple analytical tests. When user clicks on particular test then encrypted SQL queries gets executed and corresponding output got pasted in Excel.

Now the requirement is auto-scheduling this task where user will specify date and time and at that particular time test should get executed. Also SQL queries are stored in encrypted format for security purpose so I cannot use SSIS package or SQL job agents for scheduling the tasks.

What possible approaches/workaround can be used with this particular scenario for implementing scheduler for .NET Windows Application?

Ok, I'll try to explain the approach we used. We have a web ui, a database and 2 windows services, one that is used to update the schedule information and one that is responsible for exporting to Excel.

Database

A table to store our queries together with his schedule information. A table to store all exports, so we can keep history.

Web UI

Through a webinterface we can store queries that need to be executed automatically on a scheduled basis, some hourly, some daily, some weekly and some monthly. On the interface the user can makes his disered configuration for the schedule.

When the query is saved, we immediately calculate the nextruntime of this query through a self written SQL function and store this value in the database. Each time an update happens for a record, ex query changes or the schedule info changes, we update the field lastmodified.

Services

Our first service reads in all information where the field nextruntime is not null. This information we keep in memory in an object list. Every 5 minutes we check if there is a change made to that export, because the query can be changed or the schedule information is updated. If a we find an updated record we update this information in the object list. In the same service we loop every 30 seconds over the object list and see if the nextruntime equals the actual system datetime. If so we add a record to the second table with a certain status, so the second service knows which records needs to be processed and we also keep an incremental sequence number so it exports them in order.

Our second service polls the second table and is responsible for executing the query, exporting the result to Excel, and when it's done update the nextruntime field in the first table based on the schedule information. For creating the Excel files we used the OpenXml library.

I hope it's a bit clear to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM