By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

pausing an application

P: n/a
RSH
I am writing a VB .Net App (Not ASP .Net) where I'm having an issue creating
a cancel button...
I have a situation where I have a loop that is initiated when the user
clicks on a Run button. I would like to have a Cancel button that when the
user clicks it a message button a messagebox will be displayed asking if
they would like to cancel or not...if they select yes I would like to break
out of the loop but not quit the application.

Basically I have it setup that a global variable called bRunApp = True and
when the button is clicked it changes the bRunApp value = False. in the
loop there is a check for the value;

if bRunApp = False Then
'display messagebox and breakout of the loop
EndIf

How would I do this?
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Have you tried using a Thread?

http://msdn.microsoft.com/library/de...classtopic.asp
"RSH" <wa*************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I am writing a VB .Net App (Not ASP .Net) where I'm having an issue
creating a cancel button...
I have a situation where I have a loop that is initiated when the user
clicks on a Run button. I would like to have a Cancel button that when
the user clicks it a message button a messagebox will be displayed asking
if they would like to cancel or not...if they select yes I would like to
break out of the loop but not quit the application.

Basically I have it setup that a global variable called bRunApp = True and
when the button is clicked it changes the bRunApp value = False. in the
loop there is a check for the value;

if bRunApp = False Then
'display messagebox and breakout of the loop
EndIf

How would I do this?

Nov 21 '05 #2

P: n/a
"RSH" <wa*************@yahoo.com> schrieb:
I have a situation where I have a loop that is initiated when the user
clicks on a Run button. I would like to have a Cancel button that when
the user clicks it a message button a messagebox will be displayed asking
if they would like to cancel or not...if they select yes I would like to
break out of the loop but not quit the application.

Basically I have it setup that a global variable called bRunApp = True and
when the button is clicked it changes the bRunApp value = False. in the
loop there is a check for the value;

if bRunApp = False Then
'display messagebox and breakout of the loop
EndIf


What's the problem with the solution you describe? Don't forget to call
'Application.DoEvents' from time to time to prevent the UI from being
blocked.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

P: n/a
RSH,

You can only do this when you create an extra procedure for this

\\\
MyCancelButton.visible = true
Do while swMyCancelButton is not clicked
doMySub
application.doevents
loop
MyCancelButton.visible = false
///

I hope this explains as well the rest otherwise reply and otherswise I hope
it helps.

Cor
Nov 21 '05 #4

P: n/a
Hello RSH ??? :-)
here is a complete example of how to do this copy the below code in a form
Imports System.Threading

Public Class Form1

Inherits System.Windows.Forms.Form

Private blnTrun As Boolean

Private thrTest As Thread

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

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.

Friend WithEvents TStart As System.Windows.Forms.Button

Friend WithEvents TStop As System.Windows.Forms.Button

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.TStart = New System.Windows.Forms.Button

Me.TStop = New System.Windows.Forms.Button

Me.SuspendLayout()

'

'TStart

'

Me.TStart.Location = New System.Drawing.Point(16, 40)

Me.TStart.Name = "TStart"

Me.TStart.Size = New System.Drawing.Size(248, 32)

Me.TStart.TabIndex = 0

Me.TStart.Text = "Start Thread"

'

'TStop

'

Me.TStop.Location = New System.Drawing.Point(16, 96)

Me.TStop.Name = "TStop"

Me.TStop.Size = New System.Drawing.Size(248, 32)

Me.TStop.TabIndex = 1

Me.TStop.Text = "Stop Thread"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 273)

Me.Controls.Add(Me.TStop)

Me.Controls.Add(Me.TStart)

Me.Name = "Form1"

Me.Text = "Texampe"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub TStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TStart.Click

Try

blnTrun = True

thrTest = New Thread(AddressOf ThreadRun)

thrTest.Name = "thrTest"

thrTest.Start()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Sub

Private Sub ThreadRun()

Dim iCount As Integer

Do Until Not blnTrun

Debug.WriteLine(String.Concat("thread running : ", iCount.ToString))

iCount += 1

Thread.Sleep(0)

Loop

End Sub

Private Sub TStop_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TStop.Click

Dim msg As String

Dim title As String

Dim style As MsgBoxStyle

Dim response As MsgBoxResult

msg = "Do you want to continue?"

style = MsgBoxStyle.DefaultButton2 Or _

MsgBoxStyle.Critical Or MsgBoxStyle.YesNo

title = "Thread Demonstration"

response = MsgBox(msg, style, title)

If response = MsgBoxResult.Yes Then ' User chose Yes. SO KEEP RUNNING

Else

blnTrun = False

' Perform some other action.

End If

End Sub

End Class

happy coding :-)

Michel Posseth [MCP]
"RSH" <wa*************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I am writing a VB .Net App (Not ASP .Net) where I'm having an issue
creating a cancel button...
I have a situation where I have a loop that is initiated when the user
clicks on a Run button. I would like to have a Cancel button that when
the user clicks it a message button a messagebox will be displayed asking
if they would like to cancel or not...if they select yes I would like to
break out of the loop but not quit the application.

Basically I have it setup that a global variable called bRunApp = True and
when the button is clicked it changes the bRunApp value = False. in the
loop there is a check for the value;

if bRunApp = False Then
'display messagebox and breakout of the loop
EndIf

How would I do this?

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.