void timer_Tick(object sender, EventArgs e) { int threadCount = 0; int handles = 0; processes = Process.GetProcesses(); foreach (Process proc in processes) { threadCount = threadCount + proc.Threads.Count; handles += proc.HandleCount; } UpTime = GetUptime().ToString(@"dd\.hh\:mm\:ss"); ThreadCount = threadCount; HandleCount = handles; Speed = GetCpuSpeedInGHz(); CPU.RemoveAt(0); double percentage = cpuCounter.NextValue(); Utilization = percentage.ToString(String.Format("0")) + "%"; CPU.Add(new Model(time, percentage, percentage * 2)); time = time.AddSeconds(1); if (OnTick != null) { OnTick(this, EventArgs.Empty); } }
async void Refresh() { try { Time = DateTime.Now.ToString("h:mm tt"); Day = DateTime.Now.ToString("dddd, MMMM d"); if (itr % 100 == 0) { TempNow = (await WeatherLib.WeatherAPI.GetCurrentTemperature("98004") + "°"); Conditions = await WeatherLib.WeatherAPI.GetCurrentConditions("98004"); WindSpeed = (await WeatherLib.WeatherAPI.GetWindSpeed("98004") + "mph"); Sunrise = (await WeatherLib.WeatherAPI.GetSunrise("98004")).ToString("h:mm tt"); Sunset = (await WeatherLib.WeatherAPI.GetSunset("98004")).ToString("h:mm tt"); Humidity = (await WeatherLib.WeatherAPI.GetHumidity("98004") + "%"); var f = await WeatherLib.WeatherAPI.GetForecast("98004"); Forecast.Clear(); foreach (var fx in f) { Forecast.Add(fx); } } //Webcam1 = "http://davux.gotdns.com:89/snapshot.cgi?user=admin&pwd=davehome&guid=" + Guid.NewGuid().ToString(); var pg = await DownloadPageAsync("http://localhost:9494"); XmlDocument x = new XmlDocument(); x.LoadXml(pg); //var x = await XmlDocument.LoadFromUriAsync(new Uri("http://localhost:9494")); CPU.Clear(); foreach (var cpu in x.GetElementsByTagName("cpu")) { CPU.Add(cpu.InnerText); } TotalCPU = x.GetElementsByTagName("allcpu")[0].InnerText + "%"; var m = x.GetElementsByTagName("memory")[0]; long total = long.Parse(m.Attributes.GetNamedItem("total").InnerText) / 1073741824; // # 1Gb long free = long.Parse(m.InnerText) / 1024; TotalMemory = total; UsedMemory = total - free; FreeMemory = free; Memory = string.Format("{0}Gb", free, total); } catch (Exception ex) { Debug.WriteLine(ex.Message); Day = ex.Message; } itr++; }