We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,680 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Pause Execution of a vb.net application

Hello,

is there a way I can pause and then Resume code execution by clicking a "Pause" /"Resume" button using Application.DoEvent, How? An example please.

3
Contributors
5
Replies
1 Week
Discussion Span
6 Years Ago
Last Updated
6
Views
Ayati
Newbie Poster
3 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Try something like this:

Private Sub btnLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoop.Click
        Do While Not Done
            My.Application.DoEvents()
            Do While OverDone
                My.Application.DoEvents()
            Loop
        Loop
        Started = False
        Done = False
        OverDone = False
    End Sub

  
    Private Sub btnToggleDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToggleDone.Click
        If Started Then
            Done = Not Done
        End If
    End Sub

    Private Sub btnToggleOverdone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToggleOverdone.Click
        If Started Then
            If Not Done Then
                OverDone = Not OverDone
            End If
        End If

    End Sub

The inner loop just waits untill the OverDone is toggled.

waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
Skill Endorsements: 4

Hello,
thank you for your reply. I have some questions. In my code I am retriving binary files from a database and all its related information from other tables to send them to another database using webservices. My outer loop is my records from the database, what is the inner loop?
dose btnToggleDone and btnToggleOverdone my pause and resume buttons?

thanks

Ayati
Newbie Poster
3 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Hello,
thank you for your reply. I have some questions. In my code I am retriving binary files from a database and all its related information from other tables to send them to another database using webservices. My outer loop is my records from the database, what is the inner loop?
dose btnToggleDone and btnToggleOverdone my pause and resume buttons?

thanks

No btnToggleDone would not be used in your program as that is the outer loop (just so I could run it and check it). btnToggleOverdone is your pause and resume button. One way to handle this is have the button lable say "Pause" when it is false and "Resume" when it is true.

Private Sub btnTogglePauseContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTogglePauseContinue.Click
If Started Then
If Not Done Then
OverDone = Not OverDone
End If
If OverDone = True Then
btnToggleOverdone.Text = "Resume"
Else
btnToggleOverdone.Text = "Pause"
End
End If
End Sub

waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
Skill Endorsements: 4
Private Sub btnTogglePauseContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTogglePauseContinue.Click
        If Started Then
            If Not Done Then
                OverDone = Not OverDone
            End If
            If OverDone = True Then
                btnToggleOverdone.Text = "Continue"
            Else
                btnToggleOverdone.Text = "Pause"
            End
        End If
End Sub

The last post did not have the code tags in the edit so I am posting the same code but indented (easier to read).

waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
Skill Endorsements: 4

Hi,

You can use System.Threading.Thread.Sleep(200) in the inner loop along with Application.DoEvents() to avoid CPU overhead.

Loren Soth

Lord Soth
Posting Whiz in Training
233 posts since Mar 2006
Reputation Points: 28
Solved Threads: 4
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0650 seconds using 2.65MB