Results 1 to 5 of 5

Thread: Pause Your Code

  1. #1

    Thread Starter
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Arrow Pause Your Code

    Look at post #5 for the updated code.
    Last edited by Pc_Not_Mac; Jun 23rd, 2011 at 03:18 PM.

  2. #2
    Junior Member ComputerDownloads's Avatar
    Join Date
    May 2010
    Posts
    26

    Re: Pause Your Code

    This is nice. This will help a lot on the future..

  3. #3
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Pause Your Code

    What exactly is the point of the demonstration? There's no pausing whatsoever - you can put 10 on the label instantly, or you can freeze the application. Yay.

    Can you please explain more about the demonstration? What does it do, exactly? Am I not pressing the buttons in the right order?

  4. #4

    Thread Starter
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Re: Pause Your Code

    Quote Originally Posted by minitech
    What exactly is the point of the demonstration? There's no pausing whatsoever - you can put 10 on the label instantly, or you can freeze the application. Yay.

    Can you please explain more about the demonstration? What does it do, exactly? Am I not pressing the buttons in the right order?
    Minitech, As this post is from Nov 19th, 2010 I have no idea what's wrong with code.
    It must of worked because if it did not, I would of never posted the code.
    I will upload another explain as soon as my replacement SSD will come back.
    I lost VS2010 Pro, and all my other stuff when it failed.

    Maybe by next Tuesday or Wednesday I will update the code.
    RMA takes forever.

    But, when you tried this code:
    Code:
    Imports System.Threading
    Public Class Form1
        Private Pause As New ManualResetEvent(True)
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Pause.Reset() ' Pause the code
        End Sub
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Pause.Set() 'Remove the lock
        End Sub
        Dim i As Integer
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Pause.WaitOne()
            Do Until i = 10
                i = i + 1
                Label1.Text = i
            Loop
        End Sub
    Does the Label text still count up even after you pressed Button1_Click?

    Try pressing 3, 1, 2.
    3) Starts the code.
    1) Puts a lock on it.
    2) Removes the lock.
    My Codebank:
    Windows Vista & 7 Glass Effect & Limit the amount of times your application could be opened.
    Pause Your Code & Check the OS name

    The question of whether computers can think is like the question of whether submarines can swim.

    Currently learning: Java

    Coding can be a learning experience or

  5. #5

    Thread Starter
    Frenzied Member Pc_Not_Mac's Avatar
    Join Date
    Oct 2009
    Location
    localhost
    Posts
    1,206

    Re: Pause Your Code

    I have updated the code.
    I did provided minimum comments inside the code but it should not be that hard to understand.
    Use the diagram below to name the elements correctly.
    If you have any questions then ask them.

    vb.net Code:
    1. Imports System.Threading
    2.  
    3. Public Class Form1
    4.     Private NewThread As Thread
    5.     Private Pause As New ManualResetEvent(True)
    6.     Dim Desideratum_Integer As Integer = 10000
    7.    
    8.     Dim i As Integer
    9.     Private Sub SubThread()
    10.         Try
    11.             Do Until i = 10000
    12.                 Pause.WaitOne()
    13.                 i = i + 1
    14.                 lblProgress.Text = "Number Count: " & i & " out of: " & Desideratum_Integer
    15.                 lblPrecent.Text = i / Desideratum_Integer * 100 & " %"
    16.                 ProgressBar1.Value = i
    17.             Loop
    18.             lblProgress.Text = "Number Count: " & i & " out of: " & Desideratum_Integer
    19.             lblPrecent.Text = i / Desideratum_Integer * 100 & " %"
    20.             Count_Up.Text = "Start"
    21.             i = 0
    22.             ProgressBar1.Value = 0
    23.             Curr.Text = "Current Task: Done!"
    24.         Catch
    25.         End Try
    26.     End Sub
    27.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    28.         CheckForIllegalCrossThreadCalls = False
    29.         ProgressBar1.Maximum = 10000
    30.     End Sub
    31.     Private Sub Count_Up_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Count_Up.Click
    32.         NewThread = New Thread(AddressOf SubThread)
    33.         NewThread.IsBackground = True
    34.         NewThread.Start()
    35.         Curr.Text = "Current Task: Calculating."
    36.         If Count_Up.Text = "Pause" Then
    37.             Pause.Reset() ' Pause the code
    38.             Count_Up.Text = "Resume"
    39.             Curr.Text = "Current Task: Paused."
    40.         ElseIf Count_Up.Text = "Resume" Then
    41.             Pause.Set() 'Remove the lock
    42.             Count_Up.Text = "Pause"
    43.             Curr.Text = "Current Task: Calculating."
    44.         ElseIf Count_Up.Text = "Start" Then
    45.             Count_Up.Text = "Pause"
    46.         End If
    47.     End Sub
    48. End Class
    Attached Images Attached Images  
    Last edited by Pc_Not_Mac; Jun 23rd, 2011 at 03:18 PM.
    My Codebank:
    Windows Vista & 7 Glass Effect & Limit the amount of times your application could be opened.
    Pause Your Code & Check the OS name

    The question of whether computers can think is like the question of whether submarines can swim.

    Currently learning: Java

    Coding can be a learning experience or

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width