473,503 Members | 10,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pausing an application

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
4 1339
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4200
by: Srinath Avadhanula | last post by:
Hello, I am wondering if QT has something like QWaitForNextEvent() function. This function would block execution of the application till another key was pressed and then return the event...
7
7576
by: Dr. Know | last post by:
I am working on an ASP page that writes to several databases, ranging from MDBs to x-base. One of the tasks involves using an existing highest value from the DB and incrementing it before...
15
1416
by: jcrouse | last post by:
Here is my code: Dim sw As StreamWriter = File.CreateText(Application.StartupPath & "\mameversion.bat") sw.WriteLine(lblMameExePath.Text & " -help >""" & Application.StartupPath &...
1
1376
by: jcrouse | last post by:
This is sort of a revisited item from about two months ago (don't get mad Cor) with additional code. I am creating a batch file called CreateMameGames.bat. I am then running that batch file to...
7
2671
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
2
5238
by: BLUE | last post by:
I would like to pause an application while the GUI display a Label saying "Logging in...". System.Timers System.Windows.Forms.Timer System.Threading.Timer System.Threading ==Thread.Sleep ...
0
2125
by: Grayzag | last post by:
Hi there, As part of my Software course, i have to create a game. Since I originally started out with python, I was used to it being really easy to create a main loop to control the game with a...
12
3309
by: greg | last post by:
Hi, Can anyone help me with the following issue: How can I pause the execution of a program until a given file is created (by another process) in a specified directory? Any ideas would be...
2
1837
by: ahammad | last post by:
I have an MFC application that opens up a Word document for editing using automation. Is there a way to pause or freeze the MFC application while the Word doc is being edited? After the editing is...
3
3882
by: Lucress Carol | last post by:
Hi everyone, I'm having troubles with pausing and continuing MFC Thread.For test purposes I've created in my MFC Dialog application a progress Bar Control, a Start Button and a Stop Button.The...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7294
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.