Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit 84232cf

Browse files
committed
show speed
1 parent c9aa8cf commit 84232cf

File tree

3 files changed

+75
-20
lines changed

3 files changed

+75
-20
lines changed

Sample/Sample_0_FileExplorer/Forms/frmHistory.Designer.cs

+34-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sample/Sample_0_FileExplorer/Forms/frmHistory.cs

+40-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public partial class frmHistory : Form
2121
private long pendingCount = 0;
2222
private long successCount = 0;
2323

24+
private long speed = 0;
25+
private long orgDoneSize = 0;
26+
2427
private object locker = new object();
2528

2629
public frmHistory(DUWorker worker)
@@ -219,16 +222,33 @@ private void worker_OnCompleted(object sender, DUWorkerEventArgs e)
219222
item.SubItems[2].Text = GetSizeText(e.op);
220223
}
221224
}
225+
226+
//重置速度计算
227+
lock(locker)
228+
{
229+
speed = 0;
230+
orgDoneSize = 0;
231+
}
222232
}
223233

224234
private void worker_OnProgress(object sender, DUWorkerEventArgs e)
225235
{
226-
if(e.op.status == OperationStatus.Processing)
236+
if (e.op.status == OperationStatus.Processing)
227237
{
228238
lock (locker)
229239
{
230240
if (!updatedOp.Contains(e.op))
231241
updatedOp.Add(e.op, e.op);
242+
if (orgDoneSize == 0 || e.op.doneSize < orgDoneSize)
243+
{
244+
orgDoneSize = e.op.doneSize;
245+
speed = 0;
246+
}
247+
else
248+
{
249+
speed += e.op.doneSize - orgDoneSize;
250+
orgDoneSize = e.op.doneSize;
251+
}
232252
}
233253
}
234254
}
@@ -355,7 +375,8 @@ private void timer1_Tick(object sender, EventArgs e)
355375
{
356376
if (lvItems.InvokeRequired)
357377
{
358-
lvItems.Invoke(new AnonymousFunction(delegate() {
378+
lvItems.Invoke(new AnonymousFunction(delegate()
379+
{
359380
lvItems.BeginUpdate();
360381
foreach (OperationInfo op in updatedOp.Keys)
361382
{
@@ -377,24 +398,37 @@ private void timer1_Tick(object sender, EventArgs e)
377398
}
378399
}
379400
}
401+
if (btnPause.Enabled)
402+
{
403+
lock (locker)
404+
{
405+
string speedstr = Utils.HumanReadableSize(speed) + "/s";
406+
lblSpeed.Text = speedstr;
407+
//重置速度计算
408+
speed = 0;
409+
}
410+
}
411+
else
412+
{
413+
lblSpeed.Text = string.Empty;
414+
}
380415
}
381416
catch { }
382-
383417
}
384418

385419
private void RefreshControls()
386420
{
387421
btnPlay.Enabled = worker.IsPause;
388422
btnPause.Enabled = !btnPlay.Enabled;
389423
btnClean.Enabled = lvItems.Items.Count > 0;
390-
lblStatus.Text = btnPause.Enabled ? "The download/upload worker running..."
391-
: "The download/upload worker stopped. Set auto start up on settings window.";
424+
lblStatus.Text = btnPause.Enabled ? "Running..." : "Stopped";
392425
RefreshST();
393426
}
394427

395428
private void RefreshST()
396429
{
397-
lblStatusST.Text = lvItems.Items.Count.ToString() + " items, "
430+
lblStatusST.Text = lvItems.Items.Count.ToString() + " items, " + Interlocked.Read(ref successCount).ToString() + " succeed";
431+
lblStatusST.ToolTipText = lvItems.Items.Count.ToString() + " items, "
398432
+ Interlocked.Read(ref pendingCount).ToString() + " pending, "
399433
+ Interlocked.Read(ref successCount).ToString() + " succeed, "
400434
+ Interlocked.Read(ref failedCount).ToString() + " failed, "

Sample/Sample_0_FileExplorer/Forms/frmHistory.resx

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
132132
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
133133
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAC
134-
CgAAAk1TRnQBSQFMAgEBAgEAAXgBAgF4AQIBEgEAARIBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
134+
CgAAAk1TRnQBSQFMAgEBAgEAAZABAgGQAQIBEgEAARIBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
135135
AwABSAMAARIDAAEBAQABCAUAARABBRgAAYACAAGAAwACgAEAAYADAAGAAQABgAEAAoACAAPAAQABwAHc
136136
AcABAAHwAcoBpgEAATMFAAEzAQABMwEAATMBAAIzAgADFgEAAxwBAAMiAQADKQEAA1UBAANNAQADQgEA
137137
AzkBAAGAAXwB/wEAAlAB/wEAAZMBAAHWAQAB/wHsAcwBAAHGAdYB7wEAAdYC5wEAAZABqQGtAgAB/wEz

0 commit comments

Comments
 (0)