Beispiel #1
0
 static void ApplicationRuntime_TimelyInfoUpdated(TimelyInfoUpdatedEventArgs e)
 {
     Console.WriteLine("CPU: {0}%", Math.Round(e.TimelyInfo.CpuUsage, 0));
     Console.WriteLine("Memory: {0} / {1} MB",
                       Math.Round(e.TimelyInfo.PrivatePhysicalMemory, 1),
                       Math.Round(e.TimelyInfo.UsedPhysicalMemory, 1));
 }
        private static void UpdateRuntimeTimelyInfo()
        {
            while (keepUpdating)
            {
                float usage = GetCpuUsage();
                float privatePhysicalMemory =
                    (float)(Process.GetCurrentProcess().PrivateMemorySize64 / 1024.00 / 1024.00);
                ComputerInfo computerInfo = new ComputerInfo();
                float usedPhysicalMemory =
                    (float)((computerInfo.TotalPhysicalMemory - computerInfo.AvailablePhysicalMemory) / 1024.00 / 1024.00);
                timelyInfo = new RuntimeTimelyInfo();
                timelyInfo.CpuUsage = usage;
                timelyInfo.PrivatePhysicalMemory = privatePhysicalMemory;
                timelyInfo.UsedPhysicalMemory = usedPhysicalMemory;

                TimelyInfoUpdatedEventArgs e = new TimelyInfoUpdatedEventArgs(timelyInfo);
                OnTimelyInfoUpdated(e);

                Thread.Sleep(TimelyInfoUpdateInterval);
            }
        }
        private static void OnTimelyInfoUpdated(TimelyInfoUpdatedEventArgs args)
        {
            TimelyInfoUpdatedEvent handler = TimelyInfoUpdated;

            if (handler != null)
            {
                handler(args);
            }
        }