如何使用我的代码减少GUI延迟?示例欢迎
问题描述:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim ip = "www.google.com"
Dim timeout = 1000
Dim sw = New Stopwatch()
Try
Dim ping As Long = -1
sw.Start()
If My.Computer.Network.Ping(ip, timeout) Then
sw.Stop()
ping = sw.ElapsedMilliseconds
End If
If ping < 0 Then
Label2.Text = "Timed Out"
Label2.BackColor = Color.Brown
Label2.ForeColor = Color.White
ElseIf ping < 200 Then
Label2.Text = "Good Connection"
Label2.BackColor = Color.Green
Else
Label2.Text = "Bad Connection"
Label2.BackColor = Color.Red
End If
Catch ex As Exception
Label2.Text = ex.Message
Label2.BackColor = Color.Red
Console.WriteLine(ex.ToString())
End Try
End Sub
End Class
<pre lang="vb"><pre lang="vb"><pre lang="vb">
答
我已经解决了这个问题,我遇到了计时器问题。
I have resolved the issue, I ran into timer problems.
我修复了此代码中来自计时器的延迟。
I fixed the lag that was coming from the timer in this code.