计算机每隔第三次通过for/next循环小睡. [英] Computer take a nap every third time through a for/next loop.

查看:78
本文介绍了计算机每隔第三次通过for/next循环小睡.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有40多年的故障排除代码和硬件遇到的最棘手的问题. followinf代码仅是3个嵌套的for/next循环.我的两台计算机大约每隔第三次(有时是2次,有时是4次)通过内部y循环进行15毫秒的小睡.一条指令被执行,然后在下一条指令执行之前需要15毫秒.什么都没有发生,没有外部引用,没有无限循环,没有复杂的数学运算,只有简单的比较语句.没有理由让CPU停止15毫秒.

我怀疑这是硬件或操作系统问题,因为它在我的两台计算机上都执行完全相同的操作,并且都没有指示任何问题  ;使用硬件或XP Pro.我使用Norton扫描下载的所有内容,每天扫描病毒,因此我怀疑它是病毒,我运行的其他程序与此CPU一样密集,并且运行时没有出现此问题.

几乎可以肯定,VB2005是有问题的.我在一台计算机上使用vbexpress,而另一台计算机上使用vs2005.我想提交一个错误报告,但找不到错误报告部分.

我已经包含了跟踪文件中的一个页面,清楚地显示了正在发生的事情.如果有人对这种问题有想法或经验,我想听听.另外,有人可以将我指向错误报告页面吗?

谢谢
Dick

<字体color =#0000ff" size ="2">公共 功能 findNums( ByVal xin w 整数 ByVal h 整数 ) 字符串
<字体颜色=#0000 ff"size =" 2>暗

cv1 颜色=颜色.FromArgb(0)
Dim cv2 颜色= Color.FromArgb(0)
s 字符串
    s = i = 0 10
  k = 0
      Trace.WriteLine(
对于x = 0到5:时间" & DateTime.Now.ToString( "mm:ss.fff" ))
       For x = xin <字体颜色=#0000ff" size ="2">要 xin + w-1
         ;  j = 0
         Trace.WriteLine(
对于y = 0到h:时间" & DateTime.Now.ToString( "mm :ss.fff" y = 0 收件人 h
            ; 尝试
       &n bsp;     cv1 = Wrknums(i).GetPixel(k,y)
  ;            Catch
               返回 <字体颜色="#0000ff"size =" 2>             结束 尝试
          Try
              cv2 = bmp2.GetPixel(x,y)          Catch
/font> "ERROR"
            结束 尝试
         Trace.WriteLine( 同时获得两个像素:时间" & DateTime.Now.ToString( "mm:ss.fff" ))
<字体颜色=#0000ff" size ="2"> "2">(((cv1.R< 160
And cv2.R< 160) (cv1.R> = 160 cv2.R> = 160)) ((cv1.G< 100 And cv2 .G< 100) (cv1.G> = 100 <字体color =#0000ff" size ="2">和 cv2.G> = 100)) ((cv1.B< 150 cv2.B< 150) (cv1.B> = 150 并且 cv2.B> = 150)) 然后
              j = j + 1
              End         ;     Trace.WriteLine( 下一个y:" &格式(y)& "time" &  DateTime.Now.ToStrin( "mm:ss.fff" )))
         Next y
j = h + 1 然后
            ;  k = k + 1
                             End /font> 如果
        Trace.WriteLine( "Next x:" &  DateTime.Now.ToString( "mm:ss.fff" x
k = w 然后
          s = Format(i)& "/" &格式(x)
         Trace.WriteLine(
"return num"         返回 如果
    Next i
Trace.WriteLine(
结束i,返回错误" & s& "time" & DateTime.Now.ToString( "mm:ss.fff" )))
重新
转动 "ERROR"
结束 <字体颜色=#0000ff" size ="2">功能

跟踪文件中的页面:

对于x = 0到5:时间40:29.359
对于y = 0到h:时间40:29.390
得到两个像素:时间40:29.390
下一个y:0时间40:29.406
得到两个像素:时间40:29.406
下一个y:1次40:29.406
同时获得两个像素:时间40:29.406
下一个y:2次40:29.406
同时获得两个像素:时间40:29.406
下一个y:3次40:29.421
得到两个像素:时间40:29.421
下一个y:4次40:29.421
得到两个像素:时间40:29.421
下一个y: 5次40:29.421
得到两个像素:时间40:29.421
下一个y:6次40:29.437
得到两个像素:时间40:29.437
下一个y:7次40:29.437
同时获得两个像素:时间40:29.437
下一个y:8次获得40:29.437
同时获得两个像素:时间40:29.437
下一个y:9次40:29.437
同时获得两个像素:时间40:29.453
下一个y:10次40:29.453
下一个x:71次40:29.453
y = 0到h:时间40:29.453
得到两个像素:时间40:29.453
下一个y:0时间40:29.453
得到两个像素:时间40:29.468
下一个y:1次40:29.468
得到两个像素:时间40:29.468
下一个y:2次40:29.468
得到两个像素:时间40:29.468
下一个y :3时间40:29.468
两个像素均获得时间:时间40:29.468
下一个y:4时间40:29.484
两个像素均获得时间:时间40:29.484
下一个y:5时间40:29.484
得到两个像素:时间40:29.484
下一个y:6时间40:29.484
得到两个像素:时间40:29.484
下一个y:7时间40 :29.500
得到两个像素:时间40:29.500
下一个y:8时间40:29.500
得到两个像素:时间40:29.500
下一个y:9时间40:29.500
获得两个像素:时间40:29.500
下一个y:10时间40:29.500
下一个x:72时间40:29.515
对于y = 0到h:时间40: 29.515
同时获得了两个像素:时间40:29.5 15
下一个y:0时间40:29.515
得到两个像素:时间40:29.515
下一个y:1时40:29.515
得到两个像素:时间40:29.515
下一个y:2次40:29.531
得到两个像素:时间40:29.531
下一个y:3次40:29.531
得到两个像素:时间40:29.531
下一个y:4次40:29.531
得到两个像素:时间40:29.531
下一个y:5次40:29.531
得到两个像素:时间40:29.546
下一个y:6次40:29.546
得到两个像素:时间40:29.546
下一个y:7次40:29.546
得到两个像素:时间40:29.546
下一个y: 8次40:29.546
得到两个像素:时间40:29.562
下一个y:9时间40:29.562
得到两个像素:时间40:29.562
下一个y:10次40:29.562
下一个x:73时间40:29.562
对于y = 0到h:时间40:29.562
同时获得两个像素:时间40:29.578
下一个y:0时间40:29.578
得到两个像素:时间40:29.578
下一个y:1时间40:29.578
得到两个像素:时间40:29.578
下一个y:2时间40 :29.578
同时获得两个像素:时间4 0:29.578
下一个y:3次40:29.593
下一个y:4次40:29.593
下一个y:4次40:29.593
得到两个像素:时间40: 29.593
下一个y:5次40:29.593
得到两个像素:时间40:29.593
下一个y:6个时间40:29.593
得到两个像素:时间40:29.609
下一个y:7次40:29.609
得到两个像素:时间40:29.609
下一个y:8个时间40:29.609
得到两个像素:时间40:29.609
下一个y:9次40:29.609
同时获得两个像素:时间40:29.625
下一个y:10次40:29.625
下一个x:74次40:29.625


Hi All,

I have the wierdest problem I have come across in my 40 some years of troubleshooting code and hardware.  The followinf code is simply 3 nested for/next loops.  About every third time (sometimes 2, sometimes 4) through the inner, y loop both of my computers take a 15 millisecond nap.  An instruction gets performed and then it is 15 milliseconds before the next instruction is performed.  Nohing else is going on, there are no outside references, there are no endless loops, there is no complicated math, just simple compare statements.  There is no reason for the cpu to stop for 15 milliseconds.

I doubt that it is a hardware or operating system problem because it does exactly the same thing on both of my computers and neither indicates any problems with the hardware or XP Pro.  I scan every thing I download with Norton and scan for viruses every day so I doubt it is a virus,  I have other programs I run that are just as cpu intensive as this one and they run with out this problem.

It almost certainly is a problem with VB2005.  I am using vbexpress on one machine and vs2005 on the other.  I would like to make a bug report but I can not find the but bug report section.

I have included a page from the trace file whic clearly shows what is happening.  If anybody has anyideas or experience with this kind of problem, I would like to hear about.  Also, could someone point me toward the bug report page?

Thanks
Dick

Public Function findNums(ByVal xin As Integer, ByVal w As Integer, ByVal h As Integer) As String
Dim i, j, k, x, y As Short
Dim cv1 As Color = Color.FromArgb(0)
Dim cv2 As Color = Color.FromArgb(0)
Dim s As String
   s = ""
   For i = 0 To 10
      k = 0
      Trace.WriteLine(
"For x = 0 To 5: time " & DateTime.Now.ToString("mm:ss.fff"))
      For x = xin To xin + w - 1
         j = 0
         Trace.WriteLine(
"For y = 0 To h: time " & DateTime.Now.ToString("mm:ss.fff"))
         For y = 0 To h
            Try
               cv1 = Wrknums(i).GetPixel(k, y)
            Catch
               Return "ERROR"
            End Try
            Try
               cv2 = bmp2.GetPixel(x, y)
            Catch
               Return "ERROR"
            End Try
            Trace.WriteLine("Got both pixels: time " & DateTime.Now.ToString("mm:ss.fff"))
            If ((cv1.R < 160 And cv2.R < 160) Or (cv1.R >= 160 And cv2.R >= 160)) And((cv1.G < 100 And cv2.G < 100) Or (cv1.G >= 100 And cv2.G >= 100)) And
((cv1.B < 150 And cv2.B < 150) Or (cv1.B >= 150 And cv2.B >= 150)) Then
               j = j + 1
            End If
            Trace.WriteLine("Next y: " & Format(y) & " time " & DateTime.Now.ToStrin("mm:ss.fff"))
         Next y
         If j = h + 1 Then
            k = k + 1
         End If
         Trace.WriteLine("Next x: " & Format(x) & " time " & DateTime.Now.ToString("mm:ss.fff"))
      
Next x
      If k = w Then
         s = Format(i) & "/" & Format(x)
         Trace.WriteLine(
"return num " & s & " time " & DateTime.Now.ToString("mm:ss.fff"))
         Return s
      End If
   Next i
   Trace.WriteLine(
"end i, return Error " & s & " time " & DateTime.Now.ToString("mm:ss.fff"))
   Re
turn "ERROR"
End Function

Page from trace file:

For x = 0 To 5: time 40:29.359
For y = 0 To h: time 40:29.390
Got both pixels: time 40:29.390
Next y: 0 time 40:29.406
Got both pixels: time 40:29.406
Next y: 1 time 40:29.406
Got both pixels: time 40:29.406
Next y: 2 time 40:29.406
Got both pixels: time 40:29.406
Next y: 3 time 40:29.421
Got both pixels: time 40:29.421
Next y: 4 time 40:29.421
Got both pixels: time 40:29.421
Next y: 5 time 40:29.421
Got both pixels: time 40:29.421
Next y: 6 time 40:29.437
Got both pixels: time 40:29.437
Next y: 7 time 40:29.437
Got both pixels: time 40:29.437
Next y: 8 time 40:29.437
Got both pixels: time 40:29.437
Next y: 9 time 40:29.437
Got both pixels: time 40:29.453
Next y: 10 time 40:29.453
Next x: 71 time 40:29.453
For y = 0 To h: time 40:29.453
Got both pixels: time 40:29.453
Next y: 0 time 40:29.453
Got both pixels: time 40:29.468
Next y: 1 time 40:29.468
Got both pixels: time 40:29.468
Next y: 2 time 40:29.468
Got both pixels: time 40:29.468
Next y: 3 time 40:29.468
Got both pixels: time 40:29.468
Next y: 4 time 40:29.484
Got both pixels: time 40:29.484
Next y: 5 time 40:29.484
Got both pixels: time 40:29.484
Next y: 6 time 40:29.484
Got both pixels: time 40:29.484
Next y: 7 time 40:29.500
Got both pixels: time 40:29.500
Next y: 8 time 40:29.500
Got both pixels: time 40:29.500
Next y: 9 time 40:29.500
Got both pixels: time 40:29.500
Next y: 10 time 40:29.500
Next x: 72 time 40:29.515
For y = 0 To h: time 40:29.515
Got both pixels: time 40:29.515
Next y: 0 time 40:29.515
Got both pixels: time 40:29.515
Next y: 1 time 40:29.515
Got both pixels: time 40:29.515
Next y: 2 time 40:29.531
Got both pixels: time 40:29.531
Next y: 3 time 40:29.531
Got both pixels: time 40:29.531
Next y: 4 time 40:29.531
Got both pixels: time 40:29.531
Next y: 5 time 40:29.531
Got both pixels: time 40:29.546
Next y: 6 time 40:29.546
Got both pixels: time 40:29.546
Next y: 7 time 40:29.546
Got both pixels: time 40:29.546
Next y: 8 time 40:29.546
Got both pixels: time 40:29.562
Next y: 9 time 40:29.562
Got both pixels: time 40:29.562
Next y: 10 time 40:29.562
Next x: 73 time 40:29.562
For y = 0 To h: time 40:29.562
Got both pixels: time 40:29.578
Next y: 0 time 40:29.578
Got both pixels: time 40:29.578
Next y: 1 time 40:29.578
Got both pixels: time 40:29.578
Next y: 2 time 40:29.578
Got both pixels: time 40:29.578
Next y: 3 time 40:29.593
Got both pixels: time 40:29.593
Next y: 4 time 40:29.593
Got both pixels: time 40:29.593
Next y: 5 time 40:29.593
Got both pixels: time 40:29.593
Next y: 6 time 40:29.593
Got both pixels: time 40:29.609
Next y: 7 time 40:29.609
Got both pixels: time 40:29.609
Next y: 8 time 40:29.609
Got both pixels: time 40:29.609
Next y: 9 time 40:29.609
Got both pixels: time 40:29.625
Next y: 10 time 40:29.625
Next x: 74 time 40:29.625


推荐答案

好吧,我注意到了一件事(可能不是您的错误),是您有2尝试/捕捉同一子项,一个接一个,返回相同的内容....为什么不将它们组合在一起?

尝试
                cv1 = Wrknums(i).GetPixel(k) /> /font>                返回font> "ERROR"
         &nb sp; nbsp; cv2 = bmp2.GetPixel(x,y)
                                                   捕捉
         ;      返回 "ERROR"
             End 请尝试

. ..

尝试
                cv2 = bmp2.GetPixel(x,y)

            Catch
               返回 尝试 如果 ((cv1.R < 160 And cv2.R< 160) (cv1.R> = 160 cv2.R> = 160)) And ((cv1.G< 100 cv2.G< 100) (cv1.G> = 100 cv2.G> = 100)) ((cv1.B< 150 并且 cv2.B< 150) Or (cv1.B> = 150 And cv2.B> = 150)) ToStrin(
上,您正在使用format()命令,但未指定任何参数....为什么不使用CInt()?

IE ... 
s = CInt(i)& "/" & CInt(x)
s = CInt(i/x)

任何一种都可以快一点,然后使用format命令.

我现在可以找到所有内容.

Dustin.
Well, one thing i noticed, (Probably not your error), is you have 2 try/catch on the same sub, one after the other, returning the same thing....  Why not combine them?

Try
               cv1 = Wrknums(i).GetPixel(k, y)
            Catch
               Return "ERROR"
            End Try
            Try
               cv2 = bmp2.GetPixel(x, y)
            Catch
               Return "ERROR"
            End Try

Would be...

Try
               cv1 = Wrknums(i).GetPixel(k, y)
               cv2 = bmp2.GetPixel(x, y)
            Catch
               Return "ERROR"
            End Try


It seems it's slowing doing at your huge multi-part if statement...
If ((cv1.R < 160 And cv2.R < 160) Or (cv1.R >= 160 And cv2.R >= 160)) And((cv1.G < 100 And cv2.G < 100) Or (cv1.G >= 100 And cv2.G >= 100)) And
((cv1.B < 150 And cv2.B < 150) Or (cv1.B >= 150 And cv2.B >= 150)) Then

I'm sure one of the MS guys (or gals) can confirm this, but i think that the compiler will exit the if statement upon the first item that doesn't match the requirements....
So basically, one in a while, the program will have to process the entire if statement, and some times, it will exit out before it checks everything.


I'm not sure if this is a typo...but underneath your huge if statement...  the "ToStrin("mm:ss.fff"))"  is missing a 'g'  on the ToString()

And you're using the format() command, but not specifying any params....   Why not use CInt()?

IE... 
s = CInt(i) & "/" & CInt(x)
or
s = CInt (i /x)

Either one would be faster then using the format command.

It's all i can find for now.

Dustin.


这篇关于计算机每隔第三次通过for/next循环小睡.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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