Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winform thread question

Status
Not open for further replies.

eHaviv

Technical User
Oct 24, 2019
8
IL
Hi

I have a form with one button
and one textbox

In the button event I set a boolean
flag that also exists in another form method that control a loop (exit from loop)

My question is this control is ok
If not what I need to do.

Thank you.
 
With referencve to your originalthread222-1798177, incorrectly posted in the VB Classic forum

The code is somewhat ugly and cumbersome, but that's neither here nor there - your primary issue us that you have a non-yielding loop (LengthyTask),which, once entered, blocks the UI thread and does not allow any Windows messages to be processed - such a clicking a button. Simplest way to deal with this is to add an

[tt]Application.DoEvents[/tt]

just before the End While, like this:

Code:
[blue] Public Sub LengthyTask()
        While True
            If flag Then
                Exit While
            End If
            [COLOR=#F57900]Application.DoEvents()[/color]
        End While
        MsgBox("TextBox1.Text = " & TextBox1.Text)
    End Sub[/blue]

Note that your code may well still do some slightly odd things, particularly since this fix will now allow reentrancy ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top