减少while循环中的CPU使用率

时间:2013-04-20 01:34:06

标签: loops while-loop cpu-usage

如何限制while循环的CPU? (cpu使用率100%)

在这种情况下,while循环内的代码:

 Sub start()

    listenerThread = New Thread(AddressOf Listen)
    listenerThread.IsBackground = True
    listenerThread.Start()
End Sub

enter code here

 Sub Listen()
    Try
        listener = New TcpListener(New IPEndPoint(IPAddress.Any, port))

        listener.Start()
     a:          While (True)
            Thread.Sleep(600)
            Dim c As New Connection(listener.AcceptTcpClient)
            AddHandler c.GotInfo, AddressOf GotInfo
            AddHandler c.Disconnected, AddressOf Disconnected
        End While
    Catch ex As Exception
        GoTo a
    End Try
  End Sub

0 个答案:

没有答案