什么都不做,但等待循环.. [英] Do nothing but wait loop..

查看:94
本文介绍了什么都不做,但等待循环..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

sleep()方法挂起应用程序并且不响应

事件。所以,我写了一个小延迟循环,允许应用程序

来响应事件。


''使用延迟(500)延迟申请500ms。


Public blnSleepTimeExpired As Boolean

Public Sub Delay(ByVal intSleepTimems As Integer)

''设置间隔。

Dim intCount为整数

tmrDelay =新计时器

tmrDelay.Interval = intSleepTimems

blnSleepTimeExpired = False


tmrDelay.Start()

Do While(不是blnSleepTimeExpired)

intCount + = 1

If(intCount Mod 25)= 0然后DoEvents()

''Debug.WriteLine(intSleepTimems&" Count:"& intCount)

Loop < br $>
tmrDelay.Stop()

End Sub


Private Sub tmrDelay_Tick(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理tmrDelay.Tick

blnSleepTimeExpired = True

结束子


该代码大部分时间都可以工作,但是一旦

挂起应用程序。


任何人都可以帮助我使用除了等待确定之外什么都不做的代码

时间。


我对此问题有任何帮助。

谢谢。

Hello all,
The sleep() method hangs up the application and does not respond to
events. So, I wrote a small delay loop that will allow the application
to respond to events.

''Use Delay(500) to delay the application for 500ms.

Public blnSleepTimeExpired As Boolean

Public Sub Delay(ByVal intSleepTimems As Integer)
''set interval.
Dim intCount As Integer
tmrDelay = New Timer
tmrDelay.Interval = intSleepTimems
blnSleepTimeExpired = False

tmrDelay.Start()
Do While (Not blnSleepTimeExpired)
intCount += 1
If (intCount Mod 25) = 0 Then DoEvents()
''Debug.WriteLine(intSleepTimems & " Count: " & intCount)
Loop
tmrDelay.Stop()
End Sub

Private Sub tmrDelay_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrDelay.Tick
blnSleepTimeExpired = True
End Sub

The code works most of the time but hangs up the application once a
while.

Can anyone help me with code that would do nothing but wait for certain
time.

I appreciate any help on this issue.
Thanks.

推荐答案

一些vb6代码,但它可能有用


ti = timer

do

doevents

循环直到计时器> ti + 1

a bit of vb6 code, but it may work

ti=timer
do
doevents
loop until timer>ti+1


代码挂起因为你正在等待强烈。线程运行在

全速检查,如果发生了什么事情。这将会影响计算机中的所有其他进程。


在循环中睡一觉,它会冷静下来:

Do While(不是blnSleepTimeExpired)

睡眠(10)

DoEvents()

循环

IdleBrain写道:
The code hangs up because you are waiting intensely. The thread runs at
full speed checking all the time if something is happening. That will
impact all other processes in the computer.

Put a sleep in the loop, and it will calm down:

Do While (Not blnSleepTimeExpired)
Sleep(10)
DoEvents()
Loop
IdleBrain wrote:
Hello all,
sleep()方法挂起应用程序并且不响应
事件。所以,我写了一个小延迟循环,允许应用程序响应事件。

''使用延迟(500)将应用程序延迟500ms。

Public blnSleepTimeExpired As Boolean
公共子延迟(ByVal intSleepTimems As Integer)
''设置间隔。
Dim intCount As Integer
tmrDelay = New Timer
tmrDelay.Interval = intSleepTimems
blnSleepTimeExpired = False

tmrDelay.Start()
Do While(不是blnSleepTimeExpired)
intCount + = 1
如果(intCount Mod 25)= 0然后DoEvents()
''Debug.WriteLine(intSleepTimems&" Count:"& intCount)
循环
tmrDelay.Stop()
Private Sub tmrDelay_Tick(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理tmrDelay.Tick
blnSleepTimeExpired = True
结束子

该代码大部分时间都可以工作,但是一旦挂起应用程序就可以了。

任何人都可以帮助我使用除了等待某些时间之外什么都不做的代码。 />
感谢您对此问题的任何帮助。
谢谢。
Hello all,
The sleep() method hangs up the application and does not respond to
events. So, I wrote a small delay loop that will allow the application
to respond to events.

''Use Delay(500) to delay the application for 500ms.

Public blnSleepTimeExpired As Boolean

Public Sub Delay(ByVal intSleepTimems As Integer)
''set interval.
Dim intCount As Integer
tmrDelay = New Timer
tmrDelay.Interval = intSleepTimems
blnSleepTimeExpired = False

tmrDelay.Start()
Do While (Not blnSleepTimeExpired)
intCount += 1
If (intCount Mod 25) = 0 Then DoEvents()
''Debug.WriteLine(intSleepTimems & " Count: " & intCount)
Loop
tmrDelay.Stop()
End Sub

Private Sub tmrDelay_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrDelay.Tick
blnSleepTimeExpired = True
End Sub

The code works most of the time but hangs up the application once a
while.

Can anyone help me with code that would do nothing but wait for certain
time.

I appreciate any help on this issue.
Thanks.



您好,IdleBrain:

您不应该使用DoEvents运行紧密循环。你应该考虑改变你的代码

·在一个单独的线程中运行你的工作。你可以随时安然入睡。

·拆分你的工作。看到这个样本:

子工作()

''做点什么。

''等一下。

''完成剩下的工作。

结束子


转换为:


子工作( )

''做点什么。

Me.TimerJob.Interval =某个时候

Me.TimerJob.Start

结束子


子TimerJob_Tick(...)处理TimerJob.Tick

Me.TimerJob.Stop

''做的剩下的工作。

结束子


好​​吧,这最后一个解决方案很少适用,但你可能会找到一个变种或使用BackgroundWorker或以你的方式穿线喜欢。


问候。

" IdleBrain" <在************** @ yahoo.com> escribióenel mensaje新闻:11 ********************** @ j33g2000cwa.googlegr oups.com ...

|大家好,

| sleep()方法挂起应用程序,并且不响应

|事件。所以,我写了一个小延迟循环,允许应用程序

|回应活动。

|

| ''使用延迟(500)将应用程序延迟500ms。

|

|公共blnSleepTimeExpired As Boolean

|

| Public Sub Delay(ByVal intSleepTimems As Integer)

| ''设定间隔。

| Dim intCount As Integer

| tmrDelay =新计时器

| tmrDelay.Interval = intSleepTimems

| blnSleepTimeExpired = False

|

| tmrDelay.Start()

| Do While(不是blnSleepTimeExpired)

| intCount + = 1

|如果(intCount Mod 25)= 0那么DoEvents()

| ''Debug.WriteLine(intSleepTimems&" Count:"& intCount)

|循环

| tmrDelay.Stop()

|结束子

|

| Private Sub tmrDelay_Tick(ByVal sender As System.Object,ByVal e As

| System.EventArgs)处理tmrDelay.Tick

| blnSleepTimeExpired = True

|结束子

|

|该代码大部分时间都可以工作,但是挂起应用程序一次

|而。

|

|任何人都可以帮我解决那些只会等待某些事情的代码。
|时间。

|

|我对这个问题有任何帮助表示感谢。

|谢谢。

Hello, IdleBrain:

You should not run a tight loop with DoEvents. You should consider changing your code either
·Running your job in a separate thread. You can safely sleep it whenever you want.
·Splitting your job. See this sample:
Sub Job()
''Do something.
''Wait some time.
''Do the rest of the job.
End Sub

Converts to:

Sub Job()
''Do something.
Me.TimerJob.Interval = Sometime
Me.TimerJob.Start
End Sub

Sub TimerJob_Tick(...) handles TimerJob.Tick
Me.TimerJob.Stop
''Do the rest of the job.
End sub

Well, this last solution is rarely suitable, but you may find a variation or use BackgroundWorker or threading the way you like.

Regards.
"IdleBrain" <in**************@yahoo.com> escribió en el mensaje news:11**********************@j33g2000cwa.googlegr oups.com...
| Hello all,
| The sleep() method hangs up the application and does not respond to
| events. So, I wrote a small delay loop that will allow the application
| to respond to events.
|
| ''Use Delay(500) to delay the application for 500ms.
|
| Public blnSleepTimeExpired As Boolean
|
| Public Sub Delay(ByVal intSleepTimems As Integer)
| ''set interval.
| Dim intCount As Integer
| tmrDelay = New Timer
| tmrDelay.Interval = intSleepTimems
| blnSleepTimeExpired = False
|
| tmrDelay.Start()
| Do While (Not blnSleepTimeExpired)
| intCount += 1
| If (intCount Mod 25) = 0 Then DoEvents()
| ''Debug.WriteLine(intSleepTimems & " Count: " & intCount)
| Loop
| tmrDelay.Stop()
| End Sub
|
| Private Sub tmrDelay_Tick(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles tmrDelay.Tick
| blnSleepTimeExpired = True
| End Sub
|
| The code works most of the time but hangs up the application once a
| while.
|
| Can anyone help me with code that would do nothing but wait for certain
| time.
|
| I appreciate any help on this issue.
| Thanks.


这篇关于什么都不做,但等待循环..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆