Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void UpdateInfo()
- {
- try
- {
- System.Management.ObjectQuery query = new ObjectQuery("Select * FROM Win32_Battery");
- ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
- ManagementObjectCollection collection = searcher.Get();
- ManagementObjectSearcher os_searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
- var memoryCollection = os_searcher.Get();
- PerformanceCounter cpuCounter;
- cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
- while (true)
- {
- try
- {
- string power = "";
- foreach (ManagementObject mo in collection)
- {
- power = (string)mo["EstimatedChargeRemaining"].ToString();
- }
- string freeMemory = "1";
- string totalMemory = "1";
- foreach (ManagementObject mobj in os_searcher.Get())
- {
- totalMemory = mobj["TotalVirtualMemorySize"].ToString();
- freeMemory = mobj["FreeVirtualMemory"].ToString();
- }
- float usageMemory = 100 - (float.Parse(freeMemory, CultureInfo.InvariantCulture) / float.Parse(totalMemory, CultureInfo.InvariantCulture)) * 100;
- float cpuUsage = cpuCounter.NextValue();
- Application.Current.Dispatcher.Invoke(() =>
- {
- Battery.Text = power + "%";
- PowerBorder.Background = new SolidColorBrush(Color.FromArgb(255,
- (byte)(int)Funcad.TransfunctionCoda(float.Parse(power, CultureInfo.InvariantCulture), trans100In, transMaxToMin255Out),
- (byte)(int)Funcad.TransfunctionCoda(float.Parse(power, CultureInfo.InvariantCulture), trans100In, transMinToMax255Out), (byte)0));
- MemoryUsed.Text = Math.Round((decimal)usageMemory, 1).ToString() + "%";
- MemoryBorder.Background = new SolidColorBrush(Color.FromArgb(255,
- (byte)(int)Funcad.TransfunctionCoda(usageMemory, trans100In, transMinToMax255Out),
- (byte)(int)Funcad.TransfunctionCoda(usageMemory, trans100In, transMaxToMin255Out), (byte)0));
- CPU.Text = Math.Round((decimal)cpuUsage, 1).ToString() + "%";
- CPUBorder.Background = new SolidColorBrush(Color.FromArgb(255,
- (byte)(int)Funcad.TransfunctionCoda(cpuUsage, trans100In, transMinToMax255Out),
- (byte)(int)Funcad.TransfunctionCoda(cpuUsage, trans100In, transMaxToMin255Out), (byte)0));
- });
- Thread.Sleep(1000);
- }
- catch (Exception ex)
- {
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement