×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Winform thread question

Winform thread question

Winform thread question

(OP)
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.

RE: Winform thread question

(OP)
Forgot to say.
I am using vb.net

RE: Winform thread question

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

Application.DoEvents

just before the End While, like this:

CODE

 Public Sub LengthyTask()
        While True
            If flag Then
                Exit While
            End If
            Application.DoEvents()
        End While
        MsgBox("TextBox1.Text = " & TextBox1.Text)
    End Sub 

Note that your code may well still do some slightly odd things, particularly since this fix will now allow reentrancy ...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close