0

How to perform an appropriate loop

 2 years ago
source link: https://www.codesd.com/item/how-to-perform-an-appropriate-loop.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to perform an appropriate loop

advertisements

I'm trying to change a few addresses. However, I need the code to update them almost consistently. The code WORKS, BUT, when the checkbox is checked, it freezes and wont let me Unchecked it. (To stop changing the addresses)

Iv'e also tryed:

Loop While CheckBox1.CheckState = 1

But that does not help the issue.

Code:

Private Sub CheckBox1_Click(sender As Object, e As EventArgs) Handles CheckBox1.Click
    If IsProcessRunning("Notepad") = True Then
        Do
            Try
                WriteInteger("Notepad", &H49E6CC, 99)
                WriteInteger("Notepad", &H49E6D4, 99)
            Catch ex As Exception
            End Try
        Loop While True
    Else
        CheckBox1.CheckState = 0
        MessageBox.Show("Notepad Not Running!")
    End If
End Sub


The application becomes unresponsive when you click on the checkbox because you have written an infinite loop in the event handler. The main thread of the application handles the execution of the UI events.

You need to create a separated mechanism that is going to continuously executes your logic, such as a BackgroundWorker or using a separated thread.

Thus, the event handler of the check box only enables/disables the BackgroundWorker or the separated Thread.

Tags vb.net

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK