Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delaying my dll -Urgent

Status
Not open for further replies.

andyUK

Programmer
Dec 19, 2000
39
0
0
GB
I have a dll that needs delayed by about 5 seconds. The code I have been using is shown below:

current = 0
Interval = 0

current = Second(Time)

While Interval < 5
Interval = Second(Time) - current
Wend

The problem with this code is that is would tend to peak my system at 100% and stay there until the code is stopped. I need a stable way to delay this code.

Any suggestions?
 
You could use a timer!
You enable it when you need it and disable it as you get the callback!

Can you tell me why you can't syncronize it in another way?
 
While Interval < 5
Interval = Second(Time) - current
DoEvents
Wend

 
You can also use this code in your general declarations:

Private Declare Sub Sleep Lib &quot;kernel32&quot; (ByVal dwmilliseconds As Long)

and say

Sleep (5000) (in the actual code) when you need to delay your dll.
 
AndyUK -

You shouldn't user Timer or Time, since they won't handle the transition at midnight correctly. Do something like:
[tt]
Dim dtStart as Date

[tab]dtStart = Now
[tab]Do
[tab][tab]DoEvents
[tab]Loop While Abs(Datediff(&quot;s&quot;, now, dtStart) < 5
[/tt]
This will loop for 5 seconds, even when run at 23:59:56

Chip H.
 
The sleep api is the best option. No reason to reinvent the wheel. This API will pause the dll's thread for the specified time and allow all other threads to execute normally. You also won't be using any processor time. Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top