1,105,644 Community Members

Pause Execution of a vb.net application

Member Avatar
Ayati
Newbie Poster
3 posts since Jul 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 63 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 6 [?]
 
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.

Member Avatar
Ayati
Newbie Poster
3 posts since Jul 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 63 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 6 [?]
 
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

Member Avatar
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 63 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 6 [?]
 
0
 
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).

Member Avatar
Lord Soth
Posting Whiz in Training
233 posts since Mar 2006
Reputation Points: 4 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

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

Loren Soth

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article