Progress bar based on exe running process on task manager

M Indra Ruslan 241 Reputation points
2020-12-02T07:56:23.947+00:00

Hi Everyone,

I tried to code for progress bar based on running .exe file on the task manager.
If the file run, the progress bar will appear and when it done, the progress bar will finish.

Thank You very much for your help and answer

Best Regard

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,203 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,741 questions
Visual Studio Setup
Visual Studio Setup
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Setup: The procedures involved in preparing a software program or application to operate within a computer or mobile device.
1,050 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,441 Reputation points
    2020-12-02T14:30:08.08+00:00

    Hello @M Indra Ruslan

    The following has a Timer enable, checks to see if an executable is running or not and sets the ProgressBar visible accordingly. The ProgressBar.Style is Marquee in this case. I tested this with an executable running and then stopped then started etc. The executable name is ChunkIncoming.exe residing in the following folder C:\Dotnetland\SIDES MPC.

    Of course you can alter the logic in regards to .Visible to set the .Value and keep the ProgressBar visible rather than hide the progress bar.

    Public Class Form1  
        Private Const ExecutablePath As String = "C:\Dotnetland\SIDES MPC"  
        Private Const ExecutableBaseName As String = "ChunkIncoming"  
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick  
            Dim process() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName(ExecutableBaseName)  
      
            If process.FirstOrDefault() Is Nothing Then  
                ProgressBar1.Visible = False  
            Else  
      
                Dim test = process.FirstOrDefault(Function(p) p.MainModule.FileName.StartsWith(ExecutablePath))  
      
                If test.HasExited Then  
                    ProgressBar1.Visible = False  
                Else  
                    If Not ProgressBar1.Visible Then  
                        ProgressBar1.Visible = True  
                    End If  
                End If  
      
            End If  
        End Sub  
    End Class  
    

    Keep ProgressBar visible, show 100 percent done

    Public Class Form1  
        Private Const ExecutablePath As String = "C:\OED\Dotnetland\SIDES MPC\Debug"  
        Private Const ExecutableBaseName As String = "ChunkIncomingTextFile"  
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick  
            Dim process() As Process = Diagnostics.Process.GetProcessesByName(ExecutableBaseName)  
      
            If process.FirstOrDefault() Is Nothing Then  
                ProgressBar1.Visible = False  
            Else  
      
                Dim test = process.FirstOrDefault(Function(p) p.MainModule.FileName.StartsWith(ExecutablePath))  
      
                If test.HasExited Then  
                    ProgressBar1.Style = ProgressBarStyle.Blocks  
                    ProgressBar1.Value = 100  
                    Timer1.Enabled = False  
                Else  
                    If Not ProgressBar1.Visible Then  
                        ProgressBar1.Visible = True  
                    End If  
                End If  
      
            End If  
        End Sub  
    End Class  
      
    
    0 comments No comments

  2. Viorel 118.2K Reputation points
    2020-12-02T16:06:23.647+00:00

    If you mean the progress information to be displayed inside the taskbar icon of your program, then consider the TaskbarItemInfo, which is easier to use in WPF applications. Give more details about your needs.

    0 comments No comments

  3. M Indra Ruslan 241 Reputation points
    2020-12-04T08:48:09.323+00:00

    Hi Viorel-1,

    If I run the app, it will run another .exe file. The exe file will compute something during the process.
    When the exe is running the progress bar should run as well and when finished calculating the progress bar will reach its maximum value.

    I hope this is clear.

    Thanks


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.