我一个程序用了几个闹钟会不会太占资源?在闹钟里加了很多判断代码,因为做个服务器,每一秒都给客户端指令!我朋友说我的程序太占资源,用代码切换几张图片出现了闪动!是不是太占资源的原因啊?前提有个闹种没停过!有没有不用闹钟能把系统的每一秒,反映出来吗?或者要怎样才能不让图片出现闪用,我图片闪动是在固定哪一秒时切换过来,可每切换一次有很大的闪动反映!

解决方案 »

  1.   

    呵呵,你是不是用了Timer控件,Timer一般不会太占资源,问题可能是在处理图片上
      

  2.   

    楼上的,我把图片存储在程序里,还是用绝对路径图片得好?我在Timer控件加了很多判断代码不会有很大影响?速度单位还是100为一循环!有没有API获取系统时间?
      

  3.   

    settimer
    但是,哪是一样的,
    你最好给出代码,让大家帮你分析一下
      

  4.   

    通常来说,执行相同的任务不要开多个定时器,这样容易引起任务直接的交叉执行,有时这样会影响性能,更严重的情况会影响结果——这个要具体问题具体分析。无论如何,一个进程内保证任务顺序执行无论是性能上还是复杂度上都是有好处的,如下:
    ·只开一个定时器,定时间隔取任务中的最小间隔或最大公约数。
    ·定义一个任务队列,无论是循环任务还是单次任务,都记录下次执行的时间,将队列按这个时间排序。
    ·每次定时器触发后,检查当前时间>=队列中第一个任务的下次执行时间,如果为True,则:
      1)暂停定时器
      2)执行第一个任务;如果是循环任务,重新计算下次执行时间,重排队列;如果是单次任务则从队列中删除。
      3)如果新的第一个任务也到时间的,会回到2)
      4)恢复定时器
      

  5.   

    首先,按照我前面的方案,所有任务都是通过与当前时间的比较决定是否执行。
    接下来,我们来保证客户端和服务器时间的近似同步:
    客户端程序启动时,同时取得服务器时间和客户端时间,无论是网络延时的问题、还是两边本地时间设置不一致,总之会有个时差,将该时差记录下来。
    以后定期比较服务器时间和客户端时间,如果 Abs(新时差, 启动时的时差) > 许可误差,你就当作网络断线之类的严重问题处理。如果你的许可误差为 10″,变速器总超前的时间上限大约只有 20″。
      

  6.   

    有什么AIP取出系统秒数的状态值?
      

  7.   

    用 VB 自带的函数就可以了:
    Now() 完整的年月日时分秒
    Date() 仅年月日
    Time() 仅时分秒
    Timer() 从零点开始经过的秒数(带小数)
      

  8.   

    Timer1.Interval=1000 就是间隔1秒Option ExplicitPrivate Sub Form_Load()
      Label1.Caption = Time
    End SubPrivate Sub Timer1_Timer()
      Label1.Caption = Time
    End Sub
      

  9.   

    下面是事个闹钟控件里的代码:Private Sub Timer3shij_Timer()
       Dim Server_kaishilx
       '////////////////////////////////////////////////////////////////////////////////////////////时间
       '********************************************************************************************
       If sj >= 8 Then
          sj = 0
          
          '总场时间
          If shij.Caption = 43 + CLng(Lei_Cssz.Cssz_Csm("每场时间")) Then
             shij.Caption = 0
             Kjjl_Enabled = True '开奖记录一闪一闪的动态值,给闹钟[启动值]
             
          Else
             shij.Caption = shij.Caption + 1
             For Server_kaishilx = 0 To admin_server.Anumber.Caption - 1
                admin_server.sckServer(admin_server.Grid1.Cell(Server_kaishilx + 1, 1).Text).SendData "同步[时间]|" & shij.Caption & "|" & shijan.Caption & vbCrLf
             Next Server_kaishilx
          End If
             
          '沙漏时间
          Dim X As Long
          For X = 0 To 15
           If shij.Caption = (43 + CLng(Lei_Cssz.Cssz_Csm("每场时间"))) - (2 * X) Then
              shadou_sj.Picture = tkgif.sdou_sj(15 - X)
           End If
          Next X
          
          '下注时间
          If shijan.Caption > 0 Then
             shijan.Caption = shijan.Caption - 1
          End If
       Else
          sj = sj + 1
          
       End If
          
       '////////////////////////////////////////////////////////////////////////////////////////////开局时播放的前段录像
       '********************************************************************************************
       '开局时播放的前段录像
       If shij.Caption = 1 And sj = 0 And kaishilx = True Then
          Dim s As Single
          s = Rnd
          Crs1.Open "select top 1 * from lxm order by rnd(" & s & "-id)", Cnn2, 1, 1
          luxianga = Crs1.Fields(1)
          luxiangb = Crs1.Fields(2)
          Url = "\\192.168.1." & Lei_Cssz.Cssz_Csm("服务器IP") & "\真人龙虎\Video\" & luxianga
          mciSendString "close   Wmv1", 0&, 0, 0
          mciSendString "open   " & Url & "   alias   Wmv1   parent   " & Picture4.hwnd & "   style   child", 0&, 0, 0
          mciSendString "put   Wmv1   window   at   -3   0   " & Gao & "   " & Kuang, 0&, 0, 0
          
          
          If Url <> "" Then
             mciSendString "play   Wmv1", 0&, 0, 0
          Else
             MsgBox "找不到视频地址!", vbInformation + vbonly, "警告"
             End
          End If
          
          Crs1.Close
          
          Picture4.Visible = True
          
          For Server_kaishilx = 0 To admin_server.Anumber.Caption - 1
             Dim ST As String * 64
             mciSendString "status Wmv1 position", ST, Len(ST), 0
             a = Val(ST) '获取视频时间发送给客户端
             admin_server.sckServer(admin_server.Grid1.Cell(Server_kaishilx + 1, 1).Text).SendData "同步[开始]|" & luxianga & "|" & a & vbCrLf
          Next Server_kaishilx
          
          General.MediaPlayer1.FileName = App.Path & "\sound\stake.wav"               '第一场开开始音乐
          General.MediaPlayer1.play
       ElseIf shij.Caption = 22 And sj = 0 And kaishilx = True Then
          General.MediaPlayer1.FileName = App.Path & "\sound\fapai.wav"               '消牌 虎牌 龙牌 音乐
          General.MediaPlayer1.play
       End If
       
       '////////////////////////////////////////////////////////////////////////////////////////////每场结束报牌音乐
       '********************************************************************************************
       '每场结束报牌音乐
       If kaishilx = False Then
          Select Case shij.Caption & sj
             Case 7 & "0"
                musicz = 0
                General.MediaPlayer1.FileName = App.Path & "\sound\Tiger.wav"
                General.MediaPlayer1.play
                musicz = musicz + 1
             Case 24 & "0"
                General.MediaPlayer1.FileName = App.Path & "\sound\fapai.wav"               '消牌 虎牌 龙牌 音乐
                General.MediaPlayer1.play
          End Select
       End If
      

  10.   

     
       '////////////////////////////////////////////////////////////////////////////////////////////开奖记录一闪一闪的动态值,给闹钟[启动值]
       '********************************************************************************************
       '开奖记录一闪一闪的动态值,给闹钟[启动值]
       If shij.Caption = 8 And sj = 0 And Kjjl_Enabled = True Then
          kjjl0.Enabled = True
       End If
       
       '////////////////////////////////////////////////////////////////////////////////////////////下注音乐报时
       '********************************************************************************************
       '下注音乐报时
       If shij.Caption = 40 And sj = 0 And Lei_Cssz.Cssz_Csm("每场时间") = 30 Then
          General.MediaPlayer1.FileName = App.Path & "\sound\m30.wav"               '还剩30秒
          General.MediaPlayer1.play
       End If
       Select Case shijan.Caption & sj
          Case 16 & "0"
             General.MediaPlayer1.FileName = App.Path & "\sound\m15.wav"               '还剩15秒
             General.MediaPlayer1.play
          Case 11 & "0"
             General.MediaPlayer1.FileName = App.Path & "\sound\m10.wav"               '还剩10秒
             General.MediaPlayer1.play
          'Case 6 & "0"
             'General.MediaPlayer1.FileName = App.Path & "\sound\m5.wav"                '还剩5秒
             'General.MediaPlayer1.play
          Case 1 & "0"
             shadou_sj.Picture = tkgif.sdou_sj(16).Picture
             General.MediaPlayer1.FileName = App.Path & "\sound\StopStake.wav"         '停止押分
             General.MediaPlayer1.play
       End Select
        
       Select Case shij.Caption & sj
          Case 43 & "0"
             shadou_sj.Picture = tkgif.sdou_sj(16)
             mciSendString "stop    Wmv1", 0&, 0, 0 '暂停录像
             Picture1.Visible = True
             shijan.Caption = Lei_Cssz.Cssz_Csm("每场时间")
          Case (43 + CLng(Lei_Cssz.Cssz_Csm("每场时间")) - 4) & "8"
             '是否第一局
             kaishilx = False
             
             '难度吃大赔小
             If CLng(Lei_Cssz.Cssz_Csm("游戏难度")) > 0 And Int(Rnd * 6) < CLng(Lei_Cssz.Cssz_Csm("游戏难度")) Then
                If baodan.Label4(chang.Caption - 1).Caption = "龙" And Nalong + yfflong(0).Caption > Nahu + yffhu(0).Caption Then
                   baodan.Label4(chang.Caption - 1).Caption = "虎"
                   kjjl(chang.Caption - 1).Picture = App.Path & "\Pictur\ld_hu.gif"
                ElseIf baodan.Label4(chang.Caption - 1).Caption = "虎" And Nalong + yfflong(0).Caption < Nahu + yffhu(0).Caption Then
                   baodan.Label4(chang.Caption - 1).Caption = "龙"
                   kjjl(chang.Caption - 1).Picture = App.Path & "\Pictur\ld_long.gif"
                End If
                '更新小录珠
                lmb1.lda 65
             End If
             
             '随机四段录像
             If Left(luxiangb, 1) > 4 Then
                b = Int(Rnd * 4)
                If b = 0 Then b = 4
                luxiangb = b
             ElseIf Left(luxiangb, 1) > 4 And Left(luxiangb, 1) <= 8 Then
                b = Int(Rnd * 8)
                If b <= 4 Then
                   If b = 0 Then
                      b = b + 5
                   Else
                      b = b + 4
                   End If
                End If
                luxiangb = b
             End If
             Label1.Caption = luxiangb
             
             'Dim r As Single
             'r = Rnd
             're.Open "select top 1 * from " & luxiangb & " where lx='1.m1v' and y='" & baodan.Label4(chang.Caption - 1).Caption & "' order by rnd(" & r & "-id)", Cnn1, 1, 1 随机抽取
             Crs1.Open "select top 1 * from jl" & luxiangb & " where id>" & datalhh & " and y='" & baodan.Label4(chang.Caption - 1).Caption & "' order by id", Cnn2, 1, 1
             
             Label1.Caption = "select top 1 * from jl" & luxiangb & " where id>" & datalhh & " and y='" & baodan.Label4(chang.Caption - 1).Caption & "' order by id -" & Crs1.Fields(0) & "-" & Crs1.Fields(7)
             
             datalhh = Crs1.Fields(0)
             Url = ""
             mciSendString "close   Wmv1", 0&, 0, 0 '关闭录像
             Url = "\\192.168.1." & Lei_Cssz.Cssz_Csm("服务器IP") & "\真人龙虎\Video\" & Crs1.Fields(1)
             mciSendString "open   " & Url & "   alias   Wmv1   parent   " & Picture4.hwnd & "   style   child", 0&, 0, 0
             mciSendString "put   Wmv1   window   at   -3   0   " & Gao & "   " & Kuang, 0&, 0, 0
             mciSendString "seek Wmv1 to " & CLng(DateDiff("s", "0", Crs1.Fields(7)) - 2) * 25, 0, 0, 0 '是当前起始位置,单位:毫秒
             pai(0).Picture = App.Path & "\Pictur\pai_ (" & Crs1.Fields(4) & ").gif"
             pai(1).Picture = App.Path & "\Pictur\pai_ (" & Crs1.Fields(4) & ").gif"
        
             '//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
             '客户端同步信息*****************************************************************
             Dim i_server As Integer
             For i_server = 0 To admin_server.Anumber.Caption - 1
                If Server_RemoteClient(admin_server.Grid1.Cell(i_server + 1, 1).Text) = False Then '检测用户是否同步过了 [主要起同步后,再不需要同步减少循环数据]
                   If kaishilx = False Then
                      Dim ludan As Integer
                      Dim lddata As String
                      For ludan = 0 To chang.Caption - 2
                         lddata = lddata & "|" & baodan.Label4(ludan).Caption
                      Next ludan
                      admin_server.sckServer(admin_server.Grid1.Cell(i_server + 1, 1).Text).SendData "同步[开奖记录]|" & chang.Caption - 2 & "|" & ludan1.Caption & "|" & ludan2.Caption & lddata & vbCrLf
                   End If
                   admin_server.sckServer(admin_server.Grid1.Cell(i_server + 1, 1).Text).SendData "同步[游戏]|" & Crs1.Fields(2) & "|" & chang.Caption - 1 & _
                                                                                  "|" & Crs1.Fields(1) & "|" & CLng(DateDiff("s", "0", Crs1.Fields(7)) - 2) * 25 & "|" & Crs1.Fields(4) & "|" & Crs1.Fields(6) & _
                                                                                  "|" & Timer1.Enabled & "|" & Timer3shij.Enabled & _
                                                                                  "|" & kjjl0.Enabled & "|" & Kjjl_timer & _
                                                                                  "|" & jiu.Caption & _
                                                                                  "|" & ludan1.Caption & "|" & ludan2.Caption & "|" & Zhi & _
                                                                                  vbCrLf
                Else
                    admin_server.sckServer(admin_server.Grid1.Cell(i_server + 1, 1).Text).SendData "同步[当场结果]|" & Crs1.Fields(2) & "|" & chang.Caption - 1 & _
                                                                                      "|" & Crs1.Fields(1) & "|" & CLng(DateDiff("s", "0", Crs1.Fields(7)) - 2) * 25 & "|" & Crs1.Fields(4) & "|" & Crs1.Fields(6) & vbCrLf
                End If
             Next i_server
          
             '客户端同步信息*****************************************************************
             '//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
             
             '播放音乐时存储的牌值
             wmvlongp = Crs1.Fields(6) '龙
             wmvhup = Crs1.Fields(4)   '虎
             
             Crs1.Close
             
             
             
          Case (43 + CLng(Lei_Cssz.Cssz_Csm("每场时间")) - 3) & "8"
          
             If Url <> "" Then
                mciSendString "play Wmv1", 0&, 0, 0 '定位后再播放
             Else
                MsgBox "找不到视频地址!", vbInformation + vbonly, "警告"
                End
             End If
             
          Case (43 + CLng(Lei_Cssz.Cssz_Csm("每场时间")) - 2) & "8"
          
             Picture1.Visible = False
             
       End Select
       
    End Sub
      

  11.   

    我晕没人帮我了吗?怎么利用AIP时间函数优化上面的代码