Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:36:05+00:00 2026-06-15T09:36:05+00:00

This is my app, you can see 3 buttons, start button enabled, pause disabled

  • 0

This is my app, you can see 3 buttons, start button enabled, pause disabled and stop disabled.

enter image description here

The problem is I have a separated thread in my form to make a “process” (and to print the information in the black richtextbox), and my intention is to can pause it or stop it, but when I launch the thread, the pause button and stop button turns Enabled to disabled in a second.

I can tell the form to wait after launching the thread with a _WaitHandle_FirstThreadDone.WaitOne() and then i can see enabled the pause and the stop buttons, but then the problem is my app hangs until the “process” is done.. so I can’t push any button.

Please, I need help to make this…

The important part of my form:

Public Class Form1

#Region "Append text function"

    ' Append Text
    Public Sub AppendText(box As RichTextBox, color As Color, text As String)

        Control.CheckForIllegalCrossThreadCalls = False

        Dim start As Integer = box.TextLength
        box.AppendText(text)
        Dim [end] As Integer = box.TextLength

        ' Textbox may transform chars, so (end-start) != text.Length
        box.[Select](start, [end] - start)
        If True Then
            box.SelectionColor = color
            ' could set box.SelectionBackColor, box.SelectionFont too.
        End If
        box.SelectionLength = 0
        ' clear
    End Sub

#End Region


#Region "Thread"

    Public _WaitHandle_FirstThreadDone As New System.Threading.AutoResetEvent(False)

    Public Sub ThreadProc(ByVal aDir As DirectoryInfo)

        Dim aFile As FileInfo

        For Each aFile In aDir.GetFiles()

            If accepted_extensions.ToLower.Contains(aFile.Extension.ToLower) Then

                ' print output
                AppendText(consolebox, Color.Yellow, "Processing: ")
                AppendText(consolebox, Color.White, aFile.ToString() + vbNewLine)
                consolebox.ScrollToCaret()
                processedfiles += 1
                totalfiles_label.Text = "Processed " + processedfiles.ToString() + " of " + totalfiles.ToString() + " total video files"

                ' MEDIAINFO:  (ac3, dts, wav and multitrack)
                If ac3 = True Or dts = True Or wav = True Or multitrack = True Then

                    MI.Open(aFile.FullName)

                    Dim Pos As Integer = 0
                    To_Display = Nothing

                    While Pos < MI.Count_Get(StreamKind.Audio)

                        ' AC-3
                        If ac3 = True Then
                            If MI.Get_(StreamKind.Audio, Pos, "Format").ToString() = "AC-3" Then
                                results_box.AppendText("AC3 Track: " + aFile.FullName.ToString() + vbNewLine)
                                results_box.SelectionStart = results_box.Text.Length
                                results_box.ScrollToCaret()
                                problems += 1
                                problems_label.Text = problems.ToString() + " problems found"
                            End If
                        End If

                        System.Math.Max(System.Threading.Interlocked.Increment(Pos), Pos - 1)
                    End While
                End If
            End If
        Next

        _WaitHandle_FirstThreadDone.Set()
    End Sub

#End Region




#Region "Organize function"

    Public Sub MediaInfo(Directory)
        Dim MyDirectory As DirectoryInfo
        MyDirectory = New DirectoryInfo(NameOfDirectory)
        MediaInfoWorkWithDirectory(MyDirectory)
    End Sub

    Public Sub MediaInfoWorkWithDirectory(ByVal aDir As DirectoryInfo)
        Dim nextDir As DirectoryInfo
        Dim t As New Threading.Thread(AddressOf ThreadProc)
        t.Start(aDir)
        '
        For Each nextDir In aDir.GetDirectories
            If playlist = True Then
                Using writer As StreamWriter = New StreamWriter(aDir.FullName & "\" & nextDir.Name & "\" & nextDir.Name & ".m3u", False, System.Text.Encoding.UTF8)
                    'overwrite existing playlist
                End Using
            End If
            MediaInfoWorkWithDirectory(nextDir)
        Next
    End Sub

#End Region




#Region "Action buttons"

    ' start button
    Public Sub Button2_Click(sender As Object, e As EventArgs) Handles start_button.Click


                consolebox.Clear()

                ' pause / cancel button ON
                start_button.Enabled = False
                pause_button.Enabled = True
                cancel_button.Enabled = True

                ' Organization process
                NameOfDirectory = userSelectedFolderPath
                MediaInfo(NameOfDirectory)
                '  _WaitHandle_FirstThreadDone.WaitOne()
                consolebox.AppendText(vbNewLine + "[+] Organization finalized!" + vbNewLine)
                consolebox.Refresh()
                consolebox.SelectionStart = consolebox.Text.Length
                consolebox.ScrollToCaret()

                ' pause / cancel button OFF
                start_button.Enabled = True
                pause_button.Enabled = False
                cancel_button.Enabled = False

    End Sub

#End Region


    Private Sub pause_button_Click(sender As Object, e As EventArgs) Handles pause_button.Click
        paused = True
    End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:36:07+00:00Added an answer on June 15, 2026 at 9:36 am

    The reason the app hangs is the program is blasting through data sequentially. You should add an if statement inside the part that is looping to check for the pause condition in between processing. Its not a good idea to put the on/off controls inside the subroutine like you have because it can only enable the buttons after everything has completed.

    I.E to stop the process

    For i to 10 Do
    If checkbox1.checked = True then Exit Sub 'check for stop condition
    'process videos
    Loop
    

    To pause it you could implement a stop but make it remember where to start when resumed.

    Also why do you have faces of death? That stuff kills braincells.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have createn an app, this app can be found here Everything is working
I have this app (contacts style) in which you can add instances to a
I implemented some app that can start Play Store. This is some kind of
I have an app that can make modify images. In some cases, this makes
I have a simple app where you can login it looks like this: {{#view
I have do this simple app, in this app when I click on start
I'm writing a silverlight application that resembles a shopping cart system. This app can
I can successfully do this: App.SomeCollection = Backbone.Collection.extend({ comparator: function( collection ){ return( collection.get(
I use a script which opens the story editor like this: app.menuActions.itemByID(119793).invoke(); How can
Hello i can't import the R with the layouts resources from my app this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.