Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 7k
Category:

ADO-ODBC

Development Platform:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Diagnostics;
  8. namespace ch4_2
  9. {
  10. /// <summary>
  11. /// Form1 的摘要说明。
  12. /// </summary>
  13. public class Form1 : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.ListBox listBox1;
  16. private System.Windows.Forms.GroupBox groupBox1;
  17. private System.Windows.Forms.GroupBox groupBox2;
  18. private System.Windows.Forms.ListView listView1;
  19. private System.Windows.Forms.ColumnHeader columnHeader1;
  20. private System.Windows.Forms.ColumnHeader columnHeader2;
  21. /// <summary>
  22. /// 必需的设计器变量。
  23. /// </summary>
  24. private System.ComponentModel.Container components = null;
  25. public Form1()
  26. {
  27. //
  28. // Windows 窗体设计器支持所必需的
  29. //
  30. InitializeComponent();
  31. DisplayModuals();
  32. DisplayMemory();
  33. //
  34. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  35. //
  36. }
  37. private void DisplayModuals()
  38. {
  39. Process[] ch42;
  40. ProcessModuleCollection modules;
  41. //通过进程名获取进程
  42. ch42 = Process.GetProcessesByName("ch4_2");
  43. // 获得模块集合
  44. modules = ch42[0].Modules;
  45. // 将库名加入listBox1中
  46. foreach (ProcessModule aModule in modules)
  47. {
  48. this.listBox1.Items.Add(aModule.ModuleName);
  49. }
  50. }
  51. /// <summary>
  52. /// 清理所有正在使用的资源。
  53. /// </summary>
  54. protected override void Dispose( bool disposing )
  55. {
  56. if( disposing )
  57. {
  58. if (components != null) 
  59. {
  60. components.Dispose();
  61. }
  62. }
  63. base.Dispose( disposing );
  64. }
  65. #region Windows Form Designer generated code
  66. /// <summary>
  67. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  68. /// 此方法的内容。
  69. /// </summary>
  70. private void InitializeComponent()
  71. {
  72. this.listBox1 = new System.Windows.Forms.ListBox();
  73. this.groupBox1 = new System.Windows.Forms.GroupBox();
  74. this.groupBox2 = new System.Windows.Forms.GroupBox();
  75. this.listView1 = new System.Windows.Forms.ListView();
  76. this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
  77. this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
  78. this.groupBox1.SuspendLayout();
  79. this.groupBox2.SuspendLayout();
  80. this.SuspendLayout();
  81. // 
  82. // listBox1
  83. // 
  84. this.listBox1.ItemHeight = 12;
  85. this.listBox1.Location = new System.Drawing.Point(24, 32);
  86. this.listBox1.Name = "listBox1";
  87. this.listBox1.Size = new System.Drawing.Size(240, 112);
  88. this.listBox1.Sorted = true;
  89. this.listBox1.TabIndex = 0;
  90. // 
  91. // groupBox1
  92. // 
  93. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  94. this.listBox1});
  95. this.groupBox1.Location = new System.Drawing.Point(16, 16);
  96. this.groupBox1.Name = "groupBox1";
  97. this.groupBox1.Size = new System.Drawing.Size(288, 160);
  98. this.groupBox1.TabIndex = 2;
  99. this.groupBox1.TabStop = false;
  100. this.groupBox1.Text = "进程加载的库";
  101. // 
  102. // groupBox2
  103. // 
  104. this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
  105. this.listView1});
  106. this.groupBox2.Location = new System.Drawing.Point(16, 192);
  107. this.groupBox2.Name = "groupBox2";
  108. this.groupBox2.Size = new System.Drawing.Size(288, 208);
  109. this.groupBox2.TabIndex = 3;
  110. this.groupBox2.TabStop = false;
  111. this.groupBox2.Text = "进程内存使用详细信息";
  112. // 
  113. // listView1
  114. // 
  115. this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  116. this.columnHeader1,
  117. this.columnHeader2});
  118. this.listView1.Location = new System.Drawing.Point(24, 32);
  119. this.listView1.Name = "listView1";
  120. this.listView1.Size = new System.Drawing.Size(240, 160);
  121. this.listView1.TabIndex = 0;
  122. this.listView1.View = System.Windows.Forms.View.Details;
  123. // 
  124. // columnHeader1
  125. // 
  126. this.columnHeader1.Text = "内存使用类别";
  127. this.columnHeader1.Width = 123;
  128. // 
  129. // columnHeader2
  130. // 
  131. this.columnHeader2.Text = "大小";
  132. // 
  133. // Form1
  134. // 
  135. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  136. this.ClientSize = new System.Drawing.Size(320, 421);
  137. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  138.   this.groupBox2,
  139.   this.groupBox1});
  140. this.Name = "Form1";
  141. this.Text = "进程详细信息";
  142. this.groupBox1.ResumeLayout(false);
  143. this.groupBox2.ResumeLayout(false);
  144. this.ResumeLayout(false);
  145. }
  146. #endregion
  147. private void DisplayMemory()
  148. {
  149. Process[] ch42;
  150. ProcessModuleCollection modules;
  151. ch42 = Process.GetProcessesByName("ch4_2");
  152. //获取专用内存大小
  153. int privateMemory=ch42[0].PrivateMemorySize;
  154. string[] subitems={"专用内存",(privateMemory/1024).ToString()+" K"};
  155. ListViewItem item=new ListViewItem(subitems);
  156. this.listView1.Items.Add(item);
  157.              
  158. //获取峰值虚拟内存大小
  159. int peakVirtualMemorySize=ch42[0].PeakVirtualMemorySize;
  160. string[] subitems1={"最大虚拟内存",(peakVirtualMemorySize/1024).ToString()+" K"};
  161. ListViewItem item1=new ListViewItem(subitems1);
  162. this.listView1.Items.Add(item1);
  163. //获取峰值分页内存大小
  164. int peakPagedMemorySize=ch42[0].PeakPagedMemorySize;
  165. string[] subitems2={"最大分页内存大小",(peakPagedMemorySize/1024).ToString()+" K"};
  166. ListViewItem item2=new ListViewItem(subitems2);
  167. this.listView1.Items.Add(item2);
  168. //获取分页的系统内存大小
  169. int pagedSystemMemorySize=ch42[0].PagedSystemMemorySize;
  170. string[] subitems3={"分页的系统内存大小",(pagedSystemMemorySize/1024).ToString()+" K"};
  171. ListViewItem item3=new ListViewItem(subitems3);
  172. this.listView1.Items.Add(item3);
  173. //获取分页的内存大小
  174. int pagedMemorySize=ch42[0].PagedMemorySize;
  175. string[] subitems4={"分页的内存大小",(pagedMemorySize/1024).ToString()+" K"};
  176. ListViewItem item4=new ListViewItem(subitems4);
  177. this.listView1.Items.Add(item4);
  178. //获取未分页的系统内存大小。
  179. int nonpagedSystemMemorySize=ch42[0].NonpagedSystemMemorySize;
  180. string[] subitems5={"未分页的系统内存大小",(nonpagedSystemMemorySize/1024).ToString()+" K"};
  181. ListViewItem item5=new ListViewItem(subitems5);
  182. this.listView1.Items.Add(item5);
  183. //获取物理内存使用情况
  184. int  memorySize=ch42[0].WorkingSet;
  185. string[] subitems6={"物理内存大小",(memorySize/1024).ToString()+" K"};
  186. ListViewItem item6=new ListViewItem(subitems6);
  187. this.listView1.Items.Add(item6);
  188. //获取进程的虚拟内存大小
  189. int  virtualMemorySize=ch42[0].VirtualMemorySize;
  190. string[] subitems7={"虚拟内存大小",(virtualMemorySize/1024).ToString()+" K"};
  191. ListViewItem item7=new ListViewItem(subitems7);
  192. this.listView1.Items.Add(item7);
  193. }
  194. /// <summary>
  195. /// 应用程序的主入口点。
  196. /// </summary>
  197. [STAThread]
  198. static void Main() 
  199. {
  200. Application.Run(new Form1());
  201. }
  202.       
  203.     
  204.          }
  205. }