C#实现对远程服务器的内存和CPU监控
2016-07-04 20:50
393 查看
C#实现对远程服务器的内存和CPU监控小记
1、 主要使用到的组件有System.Management.dll
2、 主要类为 :ManagementScope
连接远程服务器示例代码:
View Code
暂时就到这儿了。
1、 主要使用到的组件有System.Management.dll
2、 主要类为 :ManagementScope
连接远程服务器示例代码:
public delegate void DelReadStdOutput(string result); public delegate void DelReadErrOutput(string result); public event DelReadStdOutput ReadStdOutput; public event DelReadErrOutput ReadErrOutput; /// <summary> /// 注册事件 /// </summary> private void Init() { ReadStdOutput += new DelReadStdOutput(ReadStdOutputAction); ReadErrOutput += new DelReadErrOutput(ReadErrOutputAction); } //----------------------部分实现代码================== using (p = new Process()) { //pause -- 停止 p.StartInfo.FileName = fileName; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.EnableRaisingEvents = true; p.Exited += new EventHandler(p_Exited); p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived); p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived); p.Start(); //读取输出: p.BeginErrorReadLine(); p.BeginOutputReadLine(); p.WaitForExit(); } void p_OutputDataReceived(object sender, DataReceivedEventArgs e) { this.lab_tips.Text = "开始读取数据...读取时间可能有点长,请耐心等待!"; if (e.Data != null) { this.Invoke(ReadStdOutput, new object[] { e.Data }); } } // 读取进程信息: public void ReadStdOutputAction(string s) { if (num > 1) { budiler.AppendLine(s); } this.textBox1.Text = budiler.ToString(); num++; }
View Code
暂时就到这儿了。
相关文章推荐
- c# 16进制显示转化
- C# Enum,Int,String的互相转换 枚举转换
- c#断点无效:"当前不会命中断点。没有与此行关联的可执行代码。可能的原因包括:条件编译或编译器优化"
- c# listView
- c# datagridview列头添加复选框实现全选
- C# 用interface和delgate实现回调-----配合索引器实现List
- C#中字符 '\0' 是a还是空格?
- [转]DataGridView 的右键菜单(ContextMenuStrip)
- C# 中的#if、#elif、#else、#endif等条件编译符号
- C# 获取一个13位的时间戳
- 【C#编写Windows服务】
- [转]C#多线程学习 之 线程池[ThreadPool]
- 值类型 引用类型 ref out
- C# IEnumerator, IEnumerable, and Yield
- C#==>匿名方法
- C#用DataTable实现Group by数据统计
- 【音乐拼接】mp3格式
- 【音乐拼接】WAV格式
- C#调用摄像头拍摄,截图,视频
- C# 命名异常