[dba-VB] System.Timers.Timer()

jwcolby jwcolby at colbyconsulting.com
Tue May 15 13:25:17 CDT 2012


 > Is it correct understanding that you have a set of tasks to run periodically, fired by specified 
timer intervals, and when one task is running all the others are blocked?

No.  I actually have three main tasks (driven by timers) *possibly* running (which I call "stages"), 
but I have 6 timers *possibly* running plus the interface thread.

None of the tasks block any of the other tasks.

I use the timers in my clsRunState.  The run state class may monitor the click event of a dedicated 
check box which is how I start and stop each of the main tasks.  So by checking a check box, I start 
one of the three stages.  Each stage has its own check box so I can have 0 to 3 stages running 
simultaneously.

Stage1 exports data to disk files.

Stage2 pushes the files exported by stage1 to 0 to 3 virtual machines for third party processing, 
and pulls it back out of the VMs when finished.

Stage3 pulls the processed files back into SQL Server.

The reason that there are 6 timers is that clsAZManager "manages" or schedules the stages.  Its job 
is to select which supervisor is running at a given stage.  So there are three timers in clsManager 
tied to check boxes on the form which just continuously look for work for the associated stage.

However once clsManager selects a clsupervisor instance for stage1 (for instance) the supervisor has 
its own timer which it uses to perform the work for the indicated stage.  So *potentially* three 
stage timers in clsManager all firing, and *potentially* three stage timers in clsSupervisor 
instances doing the actual work.

None of these timers block any of the other timers, however the user interface (checkboxes) has to 
be able to start and stop any given stage.

Stages 1 and 3 in particular can be long running processes, taking as long as 30 seconds to a minute 
or so to process from start to finish.  So once a supervisor kicks off exporting a file to disk 
(stage1) it can't be shut down until that process finishes.  Once a supervisor kicks off importing a 
file back in to sql server (stage 3) it can't shut down until that process finished.  So I may 
"uncheck" the stage3 checkbox but it might be several minutes before the process actually stops for 
that supervisor.

I was (apparently) very occasionally getting a race condition as I would try to stop a stage, thus 
the implementation of clsTimer which I use in place of a direct timer instance (which I was using). 
  clsTimer implements the handshaking to prevent the race condition, and does so in a clean single 
location (OOP).

John W. Colby
Colby Consulting

Reality is what refuses to go away
when you do not believe in it

On 5/15/2012 1:48 PM, Salakhetdinov Shamil wrote:
> Hi John --
>
> Is it correct understanding that you have a set of tasks to run periodically, fired by specified timer intervals, and when one task is running all the others are blocked?
>
> Thank you.
>
> -- Shamil
>
>
> Tue, 15 May 2012 10:28:48 -0400 от jwcolby<jwcolby at colbyconsulting.com>:
>> Is anyone using timers to periodically run processes?
>>
>> I am (was hopefully?) having problems with apparent deadlocks and I found this on the MS site:



More information about the dba-VB mailing list