服务端界面新增一个显示对象内存使用情况。

This commit is contained in:
dathlin
2017-06-28 18:41:37 +08:00
parent 350b1f37a2
commit 52a54501c3
2 changed files with 71 additions and 6 deletions

View File

@@ -57,6 +57,10 @@
this.label1 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label_GC_Memery = new System.Windows.Forms.Label();
this.label_Pm_Memery = new System.Windows.Forms.Label();
this.statusStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -269,18 +273,64 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.label5.Font = new System.Drawing.Font("微软雅黑", 21F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label5.ForeColor = System.Drawing.Color.RoyalBlue;
this.label5.Location = new System.Drawing.Point(10, 38);
this.label5.Location = new System.Drawing.Point(10, 30);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(744, 36);
this.label5.Size = new System.Drawing.Size(548, 45);
this.label5.TabIndex = 13;
this.label5.Text = "XXXXX系统";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label6
//
this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(564, 37);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(59, 17);
this.label6.TabIndex = 14;
this.label6.Text = "对象内存:";
//
// label7
//
this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(564, 58);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(59, 17);
this.label7.TabIndex = 15;
this.label7.Text = "进程内存:";
//
// label_GC_Memery
//
this.label_GC_Memery.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label_GC_Memery.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_GC_Memery.Location = new System.Drawing.Point(629, 37);
this.label_GC_Memery.Name = "label_GC_Memery";
this.label_GC_Memery.Size = new System.Drawing.Size(125, 17);
this.label_GC_Memery.TabIndex = 16;
this.label_GC_Memery.Text = "0";
this.label_GC_Memery.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// label_Pm_Memery
//
this.label_Pm_Memery.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label_Pm_Memery.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label_Pm_Memery.Location = new System.Drawing.Point(629, 58);
this.label_Pm_Memery.Name = "label_Pm_Memery";
this.label_Pm_Memery.Size = new System.Drawing.Size(125, 17);
this.label_Pm_Memery.TabIndex = 17;
this.label_Pm_Memery.Text = "0";
this.label_Pm_Memery.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// FormServerWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(764, 481);
this.Controls.Add(this.label_Pm_Memery);
this.Controls.Add(this.label_GC_Memery);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.textBox1);
@@ -334,6 +384,10 @@
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel_time;
private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label_GC_Memery;
private System.Windows.Forms.Label label_Pm_Memery;
}
}

View File

@@ -761,6 +761,20 @@ namespace 软件系统服务端模版
thread.IsBackground = true;
thread.Start();
}
/// <summary>
/// 缓存的上次内存占用
/// </summary>
private long GC_Memery { get; set; }
private void MethodOccurEverySecond()
{
long current = GC.GetTotalMemory(false);
toolStripStatusLabel_time.Text = DateTime.Now.ToString();
label_GC_Memery.Text = current.ToString();
label_GC_Memery.BackColor = current < GC_Memery ? Color.Tomato : SystemColors.Control;
GC_Memery = current;
}
public void ThreadTimeTick()
{
@@ -769,10 +783,7 @@ namespace 软件系统服务端模版
int minute = -1;
int hour = -1;
int day = -1;
Action DTimeShow = delegate
{
toolStripStatusLabel_time.Text = DateTime.Now.ToString();
};
Action DTimeShow = MethodOccurEverySecond;
while (IsWindowShow)
{