constrain the no of sub procedure executions per second

G

Gum

I need to restrict the number of executions per second for two sub
procedures. When sum total of sub procedure executions per second is more
than a user defined number per second (e.g., five (5) per second), I need
the threads running the procedure to stop for a user defined period (e.g.,
one (1) second), while other processes can continue.
 
A

AndyM

If avgExec > userExec Then
waitTime = Now + TimeValue("00:00:05")
Do Until Now > waitTime
DoEvents
Loop
End If

DoEvents will pause execution and allow other processes to execute.
 
G

Gum

Thanks for your response. The avgExec variable, the number of executions per
sec, would be the total of the number of executions of two sub procedures per
second.

I need to find out how to get compute the 'avgExec' variable so that I can
use your procedure below to stop the execution when avgExec>userExec is true.
 
G

Gum

Perhaps, I should explain further:

I have 2 sub procedures that are run concurrently:
Sub FirstSub()
if firstCondition=True then
....

wait 0.1 sec
secondSub
end if
end sub

sub SecondSub()
if secondcondition=True Then
....
wait 0.1 sec
FirstSub

end Sub
When the instances where condition1 and condition2 occur say 1 second apart
the program yields favourable results. However, if they run without
interruption, they would together take 0.2 secs to execute and this leads to
an error. I do not want to bypass the error as the condition is not
desirable. The Wait 0.1 sec time is just sufficient for each sub procedure
to compete its task before going to the other sub.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top