获取ffmpeg占cpu使用率

Module Module1

    Sub Main()

        Dim cpu As New PerformanceCounter("Processor", "% Processor Time", "_Total")

        Dim pros As Process()
        While True
            pros = Process.GetProcesses()
            Dim appname As String = "ffmpeg"
            For Each pro As Process In pros
                If pro.ProcessName = appname Then
                    Dim percentage = Math.Round(cpu.NextValue(), 2, MidpointRounding.AwayFromZero)

                    Console.WriteLine("CPU:" & percentage.ToString)

                    Exit For
                End If
            Next
            Threading.Thread.Sleep(1000)
        End While

    End Sub

End Module

你可能感兴趣的:(vb.net)