-----
' RunTest.exe
' Version 1.0.0
' MDJ 2012/06/27
' Label1 initially displays "STOPPED"
Option Strict On
Imports System.Windows
Public Class Form1
' Global Variable
Public runControl As Boolean
' Run Button
Private Sub RunButton_Click(sender As System.Object, e As System.EventArgs) Handles RunButton.Click
runControl = True
Label1.Text = "RUNNING"
While runControl = True
RunStep()
End While
End Sub
' Stop Button
Private Sub StopButton_Click(sender As System.Object, e As System.EventArgs) Handles StopButton.Click
' With this configuration, the Stop button must be clicked twice before the While Loop will exit ???
runControl = False
Label1.Text = "STOPPED"
End Sub
Public Sub RunStep()
Dim ValueHolder As Integer
' Process some data
For i = 1 To 79
For j = 1 To 79
ValueHolder = i * j + 23
Next
Next
' Allow outside events to be processed
Application.DoEvents()
End Sub
End Class

VulpesPosted Jun 28, 2012, 8:36 AM
As the code in the RunStep() method will execute very quickly, a BackgroundWorker or multi-threading is not very suitable either.
What I'd suggest you do instead is to use a timer with a short interval, say 60 milliseconds. This doesn't use much in the way of resources and all the code will continue to execute on the user interface thread
So, I'd add a timer to your form, double click on it to add a Tick handler and change your code as follows:
Public Class Form1
' Run Button
Private Sub RunButton_Click(sender As System.Object, e As System.EventArgs) Handles RunButton.Click
Label1.Text = "RUNNING"
Timer1.Interval = 60
Timer1.Start()
End Sub
' Stop Button
Private Sub StopButton_Click(sender As System.Object, e As System.EventArgs) Handles StopButton.Click
' should now get called on first click
Timer1.Stop()
Label1.Text = "STOPPED"
End Sub
Public Sub RunStep()
Dim ValueHolder As Integer
' Process some data
For i = 1 To 79
For j = 1 To 79
ValueHolder = i * j + 23
Next
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
RunStep()
End Sub
End Class
MDavid JohnsonPosted Jun 27, 2012, 10:07 PM
-----
This message was created by Mindcracker Network Site Administration.
-----*** PLEASE DO NOT REPLY THIS MESSAGE ***
This message has been sent from an unattended email box.
Hi MDavid Johnson,
Check out these possible articles for your problem.
Title: Stop Button
1. Tab Stops in GDI+
2. How to start or stop a Windows Service using VB.NET
3. Expand the Button size on mouse click in Silverlight
4. How to start and stop database engine in SQL 2005
5. Starting and Stopping Threads in VB.NET
6. How to Start,Stop,Pause and Resume animation to a Ellipse in WPF using VB.NET
7. SpringButton
8. Button in VB.NET
9. WPF Button control in VB.NET
10. Use of button tag in HTML5
Thank you for using and supporting Mindcracker Network.
Sincerely
Mindcracker Network Administrator
www.c-sharpcorner.com
www.vbdotnetheaven.com
www.dotnetheaven.com
www.longhorncorner.com
Thank you, but none of those articles appear to address my issue.