简体   繁体   中英

Set thread to be fired at specific time

I'm refactoring a vb.net windows forms application and we have a bunch of functionality built in threads that run at all time and are placed in a sleep state once they aren't needed. Since we have threads that only need to run at specific times of day, I'm trying to get some functionality that creates and calls the threads at specific times of day, set according to a list of hours the we define.

So, I have a basic idea of how I want them to run, namely, lets give a more concrete example:

It's 2pm (14h by european time) and I want to create the thread, have it run it's course, and once it's done, close the thread until 5pm (when I want to call it again).

How can I achieve this in vb.net?

By the way, I'm using .NET 4.0.

As mrlucmorin stated it really matters how precise you must be with the timing, you could set a timer to fire (every minute, 2 minutes, 5 minutes, or even 10 minutes mattering on precision) although not optimal, have it check the system time and if 14:00:00 is between datetime.now plus 1 minute and datetime.now then create thread, have code at the end of the thread to close itself.

14:00:00 and 17:00:00 could be saved in a mysql database which could be retrieved every hour and and use a variable to test if any of the times fall between that 1 minute increment when the timer hits - if they do have it activate the associated thread in the mysql database.

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