Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

What I have tried:

I haven't any idea how or if that
Control is ok
Posted
Updated 12-Nov-19 6:55am
Comments
Richard MacCutchan 12-Nov-19 12:27pm    
What happens when you run it?
Member 13569650 12-Nov-19 12:34pm    
Sometimes do exit from loop
Sometimes stack and I need
Use the click the X to abort.

Thank you.
[no name] 12-Nov-19 12:53pm    
Sounds like your loop does prevent to serve the message pump. Try to call Application.DoEvents in the loop. Maybe not every loop but maybe every 10'th or 100'th
Member 13569650 12-Nov-19 13:05pm    
Before I do that call that I suspect it will slow down my
Method task.

I want to know if the button event
Code and the form method code
are run concurrently at all.
Member 13569650 13-Nov-19 4:01am    
I do not know how to post it I what you tried
so I post it here

========================
'
Imports System
Imports System.Windows.Forms

Module ehRegExTester

Sub Main()

Dim myForm As New Form1
myForm.ShowDialog()

End Sub

End Module


Public Class Form1

Dim message1 As String = Nothing
Dim flag As Boolean = False

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
flag = True
End Sub

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

End Class


<global.microsoft.visualbasic.compilerservices.designergenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.
<system.diagnostics.debuggernonusercode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<system.diagnostics.debuggerstepthrough()> _
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(102, 222)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(459, 22)
Me.TextBox1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(232, 104)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(234, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(688, 458)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button

End Class

=======================

1 solution

Maybe you need Application.DoEvents() in your loop, see: Application.DoEvents Method - VB.NET Language in a Nutshell, Second Edition [Book][^]
In a tight loop a Windows form application might become unresponsive.

If this does not help, please post your code in the "What I have tried" section.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900