' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.Diagnostics
Imports System.Threading

Namespace E
    Public Class Program
        Public Shared Sub Main(args As String())
            While True
                Dim p As Process() = Process.GetProcessesByName("firefox")
                If p.Length > 0 Then
                    Dim p0 As Process = p(0)
                    Dim t1 As Long = DateTime.Now.Ticks
                    Dim p0t1 As Long = p0.TotalProcessorTime.Ticks
                    Thread.Sleep(100)
                    Dim t2 As Long = DateTime.Now.Ticks
                    Dim p0t2 As Long = p0.TotalProcessorTime.Ticks
                    Dim pct As Integer = CInt((100 * (p0t2 - p0t1) \ (t2 - t1)))
                    Console.WriteLine(pct)
                Else
                    Exit While
                End If
            End While
        End Sub
    End Class
End Namespace
