CPU使用率监控办法和执行cmd命令
1.CPU监控代码如下
引用添加一下就好
#region 获取CPU使用率
#region AIP声明
[DllImport("IpHlpApi.dll")]
extern static public uint GetIfTable(byte[] pIfTable, ref uint pdwSize, bool bOrder);
[DllImport("User32")]
private extern static int GetWindow(int hWnd, int wCmd);
[DllImport("User32")]
private extern static int GetWindowLongA(int hWnd, int wIndx);
[DllImport("user32.dll")]
private static extern bool GetWindowText(int hWnd, StringBuilder title, int maxBufSize);
[DllImport("user32", CharSet = CharSet.Auto)]
private extern static int GetWindowTextLength(IntPtr hWnd);
#endregion
public static float? GetCpuUsedRate()
{
try
{
PerformanceCounter pcCpuLoad;
pcCpuLoad = new PerformanceCounter("Processor", "% Processor Time", "_Total")
{
MachineName = "."
};
pcCpuLoad.NextValue();
Thread.Sleep(1500);
float CpuLoad = pcCpuLoad.NextValue();
return CpuLoad;
}
catch
{
}
return 0;
}
#endregion
2.iis调整
禁用APS模拟
3.应用程序池调整
高级里面给
4.CMD命令执行代码
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;//是否使用操作系统shell启动
p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
p.StartInfo.CreateNoWindow = true;//不显示程序窗口
p.Start();//启动程序
string strCMD = "taskkill /f /t /im EXCEL.EXE";//CMD放置处
//向cmd窗口发送输入信息
p.StandardInput.WriteLine(strCMD + "&exit");
p.StandardInput.AutoFlush = true;
//等待程序执行完退出进程
p.WaitForExit();
p.Close();