pausing an application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RSH

    #1

    pausing an application

    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?


  • Some Guy

    #2
    Re: pausing an application

    Have you tried using a Thread?

    http://msdn.microsoft.com/library/de...classtopic.asp


    "RSH" <way_beyond_oop s@yahoo.com> wrote in message
    news:%23Ay1tbQb FHA.1504@TK2MSF TNGP15.phx.gbl. ..[color=blue]
    >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?
    >[/color]


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: pausing an application

      "RSH" <way_beyond_oop s@yahoo.com> schrieb:[color=blue]
      > 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[/color]

      What's the problem with the solution you describe? Don't forget to call
      'Application.Do Events' 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/>

      Comment

      • Cor Ligthert

        #4
        Re: pausing an application

        RSH,

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

        \\\
        MyCancelButton. visible = true
        Do while swMyCancelButto n is not clicked
        doMySub
        application.doe vents
        loop
        MyCancelButton. visible = false
        ///

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

        Cor


        Comment

        • m.posseth

          #5
          Re: pausing an application

          Hello RSH ??? :-)


          here is a complete example of how to do this copy the below code in a form


          Imports System.Threadin g

          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.

          InitializeCompo nent()

          'Add any initialization after the InitializeCompo nent() 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.Disp ose()

          End If

          End If

          MyBase.Dispose( disposing)

          End Sub

          'Required by the Windows Form Designer

          Private components As System.Componen tModel.IContain er

          '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.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

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

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

          Me.SuspendLayou t()

          '

          'TStart

          '

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

          Me.TStart.Name = "TStart"

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

          Me.TStart.TabIn dex = 0

          Me.TStart.Text = "Start Thread"

          '

          'TStop

          '

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

          Me.TStop.Name = "TStop"

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

          Me.TStop.TabInd ex = 1

          Me.TStop.Text = "Stop Thread"

          '

          'Form1

          '

          Me.AutoScaleBas eSize = 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(By Val sender As System.Object, ByVal e As
          System.EventArg s) Handles TStart.Click

          Try

          blnTrun = True

          thrTest = New Thread(AddressO f ThreadRun)

          thrTest.Name = "thrTest"

          thrTest.Start()

          Catch ex As Exception

          MsgBox(ex.ToStr ing)

          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(ByV al sender As System.Object, ByVal e As
          System.EventArg s) 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.Def aultButton2 Or _

          MsgBoxStyle.Cri tical Or MsgBoxStyle.Yes No

          title = "Thread Demonstration"

          response = MsgBox(msg, style, title)

          If response = MsgBoxResult.Ye s 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" <way_beyond_oop s@yahoo.com> wrote in message
          news:%23Ay1tbQb FHA.1504@TK2MSF TNGP15.phx.gbl. ..[color=blue]
          >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?
          >[/color]


          Comment

          Working...