How to pause a process for a given time?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a program need to check the value of a application available, and then decide whether to execute codes followed.

In order to achieve this purpose, I use DO WHILE loop to judge the value, if the value meet the condition clause, program will exit the loop. But this DO WHILE loop consumes too much CPU resource.

Now my question is whether a possible way to pause a process for a given time such as one minute?

Anyone can give me some guide on this issue? Thanks

For better understanding the scenario, please refer to following codes.

Public Function DataAccessBegin() As Boolean
Try
Dim StartTime As DateTime
StartTime = Now
Do While Application("ActiveConnections") + 1 > Application("PermitConnections")
'If StartTime.AddMinutes(1) < Now Then
Me.LblMessage1.Text = "Two当å‰æ•°æ®åº“访问用户太多,请ç¨åŽå†ä½¿ç”¨è¯¥æŠ¥è¡¨ï¼"
Me.LblMessage1.CssClass = "ERROR"
Return False
'End If
Loop
Application("ActiveConnections") = Application("ActiveConnections") + mDataRow(0).Item("FORBIDCONN")
If Application("ActiveConnections") > Application("PeakConnections") Then Application("PeakConnections") = Application("ActiveConnections")
End If
Finally
End Try
Return True
End Function


Lei Guangfu(雷光富)
 
Lei Guangfu said:
Hi,

I have a program need to check the value of a application available, and
then decide whether to execute codes followed.
In order to achieve this purpose, I use DO WHILE loop to judge the value,
if the value meet the condition clause, program will exit the loop. But this
DO WHILE loop consumes too much CPU resource.
Now my question is whether a possible way to pause a process for a given
time such as one minute?

To pause a process, you can use System.Threading.Thread.Sleep(x) where x is
the number of milisecond during which you want you process to be suspended.
However, in your particular scenario, i would simply use a Timer (the one in
System.Windows.Form that you can also find in the toolbox of the Window Form
designer) instead of looping and sleeping.
 
Back
Top