找回密码
 加入
搜索
查看: 18025|回复: 50

[AU3基础] 循环代码求解?循环里面里又循环和延时!(已解决)

 火... [复制链接]
发表于 2012-12-11 19:09:49 | 显示全部楼层 |阅读模式
本帖最后由 cfs43210 于 2012-12-12 21:02 编辑
AdlibRegister("detect2", 1000 * 60 * 30) ;30分钟
AdlibRegister("detect3", 1000 * 60 * 60) ;60分钟

While 1
        
        Sleep(1000 * 60 * 5)

        While 1

                If "ping=False" Then
                        ;代码
                        Sleep(1000 * 60 * 3)
                        ContinueLoop
                        
                ElseIf "文件<>0" Then
                        
                        If "服务器网络通" Then
                                ;代码
                                Sleep(1000 * 60 * 2)
                                ContinueLoop
                        Else
                                ;代码
                                Sleep(1000 * 60 * 30)
                                ContinueLoop
                                
                        EndIf
                        
                Else
                        ExitLoop
                EndIf

        WEnd

WEnd
这个写法不知道合适,现在问是感觉While 这个死循环工作一段时间后不会循环,象是卡死一样的,因为这个While循环有延时,不能用AdlibRegister这个函数。请问While还有什么代码这个死循环。谢谢!
发表于 2012-12-11 19:19:04 | 显示全部楼层
AdlibRegister("detect2", 1000 * 60 * 30) ;30分钟
AdlibRegister("detect3", 1000 * 60 * 60) ;60分钟
...
cfs43210 发表于 2012-12-11 19:09



    延时时间太久了,有要延时的地方,在子程序中实现,主程序可以简洁点。

    或者把"工作代码"写成子函数,然后注册为AdlibRegister指定为你要的时间就可以了。
发表于 2012-12-11 19:24:57 | 显示全部楼层
延长时间太长导致的,楼上正解!
 楼主| 发表于 2012-12-11 19:26:04 | 显示全部楼层
本帖最后由 cfs43210 于 2012-12-11 19:33 编辑

谢谢你回复!

If WinWait("连接到时出错", "", 60) Then

我是这样的延时,不好搞啊,5分钟会太长吗?不知道你说的是哪个时间过长了
AdlibRegister("detect2", 1000 * 60 * 30) ;30分钟
AdlibRegister("detect3", 1000 * 60 * 60) ;60分钟 你们说的是这2个吗?
发表于 2012-12-11 19:40:57 | 显示全部楼层
回复 4# cfs43210


    While 1
Sleep(1000 * 60 * 5)
;;工作代码
WEnd
 楼主| 发表于 2012-12-11 19:44:11 | 显示全部楼层
While 1
Sleep(1000 * 60 * 5)
;;工作代码
WEnd

这个里面还有一个While 循环,哎难搞。
发表于 2012-12-11 20:03:33 | 显示全部楼层
休眠时间太长了,15~50个毫秒就可以了~~
发表于 2012-12-11 20:07:09 | 显示全部楼层
回复 6# cfs43210


   
#include <date.au3>

Local $iTime = _NowCalc()
While 1
        Sleep(50)
        If _DateDiff('n', $iTime, _NowCalc()) = 5 Then
                $iTime = _NowCalc()
                ;工作代码
        EndIf
WEnd
 楼主| 发表于 2012-12-11 20:26:38 | 显示全部楼层
回复 8# user3000

谢谢8楼,看看这个能不能套用
 楼主| 发表于 2012-12-11 20:36:09 | 显示全部楼层
本帖最后由 cfs43210 于 2012-12-11 20:43 编辑

回复 8# user3000

#include <date.au3>

Local $iTime = _NowCalc()
While 1
        Sleep(50)
        If _DateDiff('n', $iTime, _NowCalc()) = 5 Then
                $iTime = _NowCalc()
                ;工作代码
        EndIf
WEnd

;请问工作代码里面可以加延时?
Sleep(1000 * 60 * 30)
发表于 2012-12-11 21:09:51 | 显示全部楼层
回复 10# cfs43210


    主循环里一般不建议加入过长的延迟,那样会影响程序对其他操作的响应.

"工作代码"里一样可以用 _DateDiff 进行另一次时间判断;也可以用 AdlibRegister 函数.
比如:
AdlibRegister("detect2", 1000 * 60 * 30) ; 工作代码里注册一个延时执行的函数.

Func detect2()
  UnAdlibRegister('detect2') ; 保证了此函数只执行当次
  ;继续要执行的工作代码
EndFunc
发表于 2012-12-11 21:16:43 | 显示全部楼层
本帖最后由 netegg 于 2012-12-11 21:17 编辑

while根本就不能嵌套用,一楼的代码能运行?而且不报错?
adlib不能延时?第二个参数是干什么用的?
发表于 2012-12-11 21:18:45 | 显示全部楼层
While true
Sleep(1000 * 60 * 5)
;;工作代码
WEnd
 楼主| 发表于 2012-12-11 21:29:22 | 显示全部楼层
回复 13# lark

AdlibRegister("detect2", 1000 * 60 * 30) ;30分钟
AdlibRegister("detect3", 1000 * 60 * 60) ;60分钟

While 1
        
        Sleep(1000 * 60 * 5)

        While 1

                If ....Then
                        ;代码
                        Sleep(1000 * 60 * 3)
                        ContinueLoop
                ElseIf ... Then
                        ;代码
                        Sleep(1000 * 60 * 2)
                        ContinueLoop
                ElseIf ... Then
                        ;代码
                        Sleep(1000 * 60 * 30)
                        ContinueLoop
                Else
                        ExitLoop
                EndIf

        WEnd

WEnd
这三个都是要一直循环
 楼主| 发表于 2012-12-11 21:31:14 | 显示全部楼层
回复 11# user3000
AdlibRegister("detect2", 1000 * 60 * 30) ;30分钟
AdlibRegister("detect3", 1000 * 60 * 60) ;60分钟

While 1
        
        Sleep(1000 * 60 * 5)

        While 1

                If ....Then
                        ;代码
                        Sleep(1000 * 60 * 3)
                        ContinueLoop
                ElseIf ... Then
                        ;代码
                        Sleep(1000 * 60 * 2)
                        ContinueLoop
                ElseIf ... Then
                        ;代码
                        Sleep(1000 * 60 * 30)
                        ContinueLoop
                Else
                        ExitLoop
                EndIf

        WEnd

WEnd
这三个都是要一直循环
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-15 11:05 , Processed in 0.082167 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表