diff --git a/XCoder/Tools/FrmMD5.cs b/XCoder/Tools/FrmMD5.cs
index 2c2512f..024f186 100644
--- a/XCoder/Tools/FrmMD5.cs
+++ b/XCoder/Tools/FrmMD5.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
@@ -53,6 +54,9 @@ namespace XCoder.Tools
case RichTextBox rtb:
if (dic.TryGetValue(item.Name, out v)) rtb.Text = v + "";
break;
+ case NumericUpDown nud:
+ if (dic.TryGetValue(item.Name, out v)) nud.Value = v.ToInt();
+ break;
default:
if (item.Controls.Count > 0) LoadConfig(dic, item);
break;
@@ -80,6 +84,7 @@ namespace XCoder.Tools
case RadioButton rb: dic[item.Name] = rb.Checked; break;
case CheckBox cb: dic[item.Name] = cb.Checked; break;
case RichTextBox rtb: dic[item.Name] = rtb.Text; break;
+ case NumericUpDown nud: dic[item.Name] = nud.Value; break;
default:
if (item.Controls.Count > 0) SaveConfig(dic, item);
break;
@@ -171,12 +176,15 @@ namespace XCoder.Tools
}
// 总计算量
- var total = (Int64)Math.Pow(sb.Length, length);
- lbTotal.Text = total.ToString("n0");
+ _total = (Int64)Math.Pow(sb.Length, length);
+ lbTotal.Text = _total.ToString("n0");
return sb.ToString();
}
+ private Int64 _total;
+ private Int64 _p;
+ private Stopwatch _watch;
private async void btnMD5_Click(Object sender, EventArgs e)
{
SaveConfig();
@@ -186,13 +194,14 @@ namespace XCoder.Tools
var result = buf.ToStr().ToUpper();
var length = (Int32)numLength.Value;
- var total = (Int64)Math.Pow(chars.Length, length);
var cpu = Environment.ProcessorCount;
- var step = total / cpu;
+ var step = _total / cpu;
+ _watch = Stopwatch.StartNew();
+ rtResult.Text = null;
var btn = sender as Button;
btn.Enabled = false;
-
+ timer1.Enabled = true;
try
{
//var source = new TaskCompletionSource<String>();
@@ -212,6 +221,10 @@ namespace XCoder.Tools
finally
{
btn.Enabled = true;
+ timer1.Enabled = false;
+
+ timer1_Tick(null, null);
+ _watch.Stop();
}
}
@@ -225,6 +238,8 @@ namespace XCoder.Tools
for (var i = start; i < end && !cts.Token.IsCancellationRequested; i++)
{
+ Interlocked.Increment(ref _p);
+
// 生成字符串。倒序,逐级取余,得到字符
var n = i;
for (var j = length - 1; j >= 0; j--)
@@ -251,5 +266,16 @@ namespace XCoder.Tools
{
var chars = GetChars();
}
+
+ private void timer1_Tick(Object sender, EventArgs e)
+ {
+ lbPosition.Text = _p.ToString("n0");
+ lbProgress.Text = ((Double)_p / _total).ToString("p2");
+ lbCost.Text = _watch.Elapsed.ToString();
+
+ var speed = _p * 1000d / _watch.ElapsedMilliseconds;
+ lbSpeed.Text = speed.ToString("n0") + "/s";
+ lbMaxCost.Text = TimeSpan.FromSeconds(_total / speed).ToString();
+ }
}
}
\ No newline at end of file
diff --git a/XCoder/Tools/FrmMD5.Designer.cs b/XCoder/Tools/FrmMD5.Designer.cs
index a77d3d4..0bc2916 100644
--- a/XCoder/Tools/FrmMD5.Designer.cs
+++ b/XCoder/Tools/FrmMD5.Designer.cs
@@ -59,6 +59,12 @@
this.rbBase64 = new System.Windows.Forms.RadioButton();
this.rbHex = new System.Windows.Forms.RadioButton();
this.rbString = new System.Windows.Forms.RadioButton();
+ this.lbCost = new System.Windows.Forms.Label();
+ this.label4 = new System.Windows.Forms.Label();
+ this.lbMaxCost = new System.Windows.Forms.Label();
+ this.label6 = new System.Windows.Forms.Label();
+ this.lbSpeed = new System.Windows.Forms.Label();
+ this.label8 = new System.Windows.Forms.Label();
this.gbFunc.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numLength)).BeginInit();
this.gbSource.SuspendLayout();
@@ -70,6 +76,12 @@
//
this.gbFunc.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
+ this.gbFunc.Controls.Add(this.lbMaxCost);
+ this.gbFunc.Controls.Add(this.lbSpeed);
+ this.gbFunc.Controls.Add(this.label8);
+ this.gbFunc.Controls.Add(this.label6);
+ this.gbFunc.Controls.Add(this.lbCost);
+ this.gbFunc.Controls.Add(this.label4);
this.gbFunc.Controls.Add(this.lbProgress);
this.gbFunc.Controls.Add(this.label7);
this.gbFunc.Controls.Add(this.lbPosition);
@@ -96,7 +108,7 @@
//
this.lbProgress.AutoSize = true;
this.lbProgress.ForeColor = System.Drawing.Color.Red;
- this.lbProgress.Location = new System.Drawing.Point(100, 267);
+ this.lbProgress.Location = new System.Drawing.Point(100, 268);
this.lbProgress.Name = "lbProgress";
this.lbProgress.Size = new System.Drawing.Size(53, 18);
this.lbProgress.TabIndex = 16;
@@ -105,7 +117,7 @@
// label7
//
this.label7.AutoSize = true;
- this.label7.Location = new System.Drawing.Point(7, 267);
+ this.label7.Location = new System.Drawing.Point(7, 268);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(98, 18);
this.label7.TabIndex = 15;
@@ -219,7 +231,7 @@
//
// btnMD5
//
- this.btnMD5.Location = new System.Drawing.Point(53, 299);
+ this.btnMD5.Location = new System.Drawing.Point(58, 444);
this.btnMD5.Margin = new System.Windows.Forms.Padding(4);
this.btnMD5.Name = "btnMD5";
this.btnMD5.Size = new System.Drawing.Size(112, 45);
@@ -394,6 +406,11 @@
this.rtPass.TabIndex = 2;
this.rtPass.Text = "NewLife";
//
+ // timer1
+ //
+ this.timer1.Interval = 500;
+ this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
+ //
// rbBase64
//
this.rbBase64.AutoSize = true;
@@ -429,6 +446,63 @@
this.rbString.Text = "字符串";
this.rbString.UseVisualStyleBackColor = true;
//
+ // lbCost
+ //
+ this.lbCost.AutoSize = true;
+ this.lbCost.ForeColor = System.Drawing.Color.Red;
+ this.lbCost.Location = new System.Drawing.Point(100, 301);
+ this.lbCost.Name = "lbCost";
+ this.lbCost.Size = new System.Drawing.Size(17, 18);
+ this.lbCost.TabIndex = 18;
+ this.lbCost.Text = "0";
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(7, 301);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(62, 18);
+ this.label4.TabIndex = 17;
+ this.label4.Text = "耗时:";
+ //
+ // lbMaxCost
+ //
+ this.lbMaxCost.AutoSize = true;
+ this.lbMaxCost.ForeColor = System.Drawing.Color.Red;
+ this.lbMaxCost.Location = new System.Drawing.Point(100, 368);
+ this.lbMaxCost.Name = "lbMaxCost";
+ this.lbMaxCost.Size = new System.Drawing.Size(17, 18);
+ this.lbMaxCost.TabIndex = 20;
+ this.lbMaxCost.Text = "0";
+ //
+ // label6
+ //
+ this.label6.AutoSize = true;
+ this.label6.Location = new System.Drawing.Point(7, 334);
+ this.label6.Name = "label6";
+ this.label6.Size = new System.Drawing.Size(62, 18);
+ this.label6.TabIndex = 19;
+ this.label6.Text = "速度:";
+ //
+ // lbSpeed
+ //
+ this.lbSpeed.AutoSize = true;
+ this.lbSpeed.ForeColor = System.Drawing.Color.Red;
+ this.lbSpeed.Location = new System.Drawing.Point(100, 334);
+ this.lbSpeed.Name = "lbSpeed";
+ this.lbSpeed.Size = new System.Drawing.Size(17, 18);
+ this.lbSpeed.TabIndex = 22;
+ this.lbSpeed.Text = "0";
+ //
+ // label8
+ //
+ this.label8.AutoSize = true;
+ this.label8.Location = new System.Drawing.Point(7, 368);
+ this.label8.Name = "label8";
+ this.label8.Size = new System.Drawing.Size(98, 18);
+ this.label8.TabIndex = 21;
+ this.label8.Text = "估算耗时:";
+ //
// FrmMD5
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
@@ -487,5 +561,11 @@
private System.Windows.Forms.RadioButton rbBase64;
private System.Windows.Forms.RadioButton rbHex;
private System.Windows.Forms.RadioButton rbString;
+ private System.Windows.Forms.Label lbCost;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.Label lbMaxCost;
+ private System.Windows.Forms.Label label6;
+ private System.Windows.Forms.Label lbSpeed;
+ private System.Windows.Forms.Label label8;
}
}
\ No newline at end of file