At first I thought I could use the trimer control, but only then knew that when the trimer was set to 100 microseconds, the entire form would be loaded and unusable. =
This use can only be used to load and delegate assignments using the loads.
CPU Usage
GetInfo GetInfo = new GetInfo (Userpercent,ram);
Thread th = new Thread (getinfo.threadprocsoft);
Th. Start ();
Defining delegate Types
delegate void Settextcallback (String str,string RAM);
<summary>
Event CPU usage for delegate execution
</summary>
public void Threadprocsoft ()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher ("SELECT * from Win32_Processor");
string usepre = null;
string rampre = null;
while (true)
{
foreach (ManagementObject myobject in searcher. Get ())
{
Usepre = myobject["Loadpercentage"]. ToString () + "%";
Lblcpu.text = myobject["Loadpercentage"]. ToString () + "%";
Mheight = Convert.ToInt32 (myobject["Loadpercentage"]. ToString ());
if (mheight = = 100)
Panel3. Height = 100;
CreateImage ();
Rampre = Memory () + "%";
}
This.settext (Usepre,rampre);
Thread.Sleep (300);
}
}
<summary>
Assign a value to the label of the CPU
</summary>
<param name= "str" ></param>
public void SetText (String str,string RAM)
{
if (lable1. invokerequired)
{
Resolve a "Access disposed handle" exception when the form is closed
while (Lable1. Ishandlecreated = = False)
{
if (lable1. Disposing | | Lable1. isdisposed) return;
}
Settextcallback d = new Settextcallback (setText);
Lable1. Invoke (d, new object[] {str,ram});
}
Else
{
Lable1. Text = str;
}
if (lable2. invokerequired)
{
Resolve a "Access disposed handle" exception when the form is closed
while (Lable2. Ishandlecreated = = False)
{
if (lable2. Disposing | | Lable1. isdisposed) return;
}
Settextcallback d = new Settextcallback (setText);
Lable2. Invoke (d, new object[] {str,ram});
}
Else
{
Lable2. Text = RAM;
}
}
C # WinForm always detects your computer's CPU usage and physical memory usage