I’m developing an application that should perform certain sql queries in different MSSQL servers after specified intervals. My thoughts are about make an array of threads and in each thread run timer in which task will run. Does it really needs to make each thread for each timer, or should I just distinguish one timer for each task (whatever timer will produce thread)? Any thoughts about implementation?
Thanks a lot, guys!
I doubt that you need to have one thread per task. It would probably suffice to create one timer per task. If a timer fires whilst another task is running then the second task will have to queue up but it doesn’t sound like that will be a great problem.
If you are going to use a Delphi
TTimerto do this you’ll need to make sure that your service has a message queue and runs a message loop on that queue. You may wish to run that message queue on a separate thread but if you do make sure that theTTimerobjects are created on that thread so that they are associated with the right message queue.You ask in the comments how to run a message loop in a thread. The following code should suffice:
This will give you all the bells and whistles of the Delphi message loop. If you want a very standard message loop you can use this:
If all you want is to pump
WM_TIMERmessages both will work but I personally would be inclined to go with the second option, the raw Win32 API version.