• R/O
  • HTTP
  • SSH
  • HTTPS

CompleteEraser: Commit


Commit MetaInfo

Revisionfd4be67b95e9fdc2c705bdb631bfe94c5f3a2b0c (tree)
Time2012-10-18 18:07:13
Authorkonekoneko <jbh03215@gmai...>
Commiterkonekoneko

Log Message

asyncを使用するようにした

Change Summary

Incremental Difference

--- a/CompleteEraser/BreakRecyleBin.cs
+++ b/CompleteEraser/BreakRecyleBin.cs
@@ -2,6 +2,8 @@
22 using System.Collections.Generic;
33 using System.Runtime.InteropServices;
44 using System.IO;
5+using System.Threading;
6+using System.Threading.Tasks;
57
68 namespace CompleteEraser
79 {
@@ -18,8 +20,9 @@ namespace CompleteEraser
1820
1921 public event ProgressingEventHandler Progressing;
2022 public event ProgressedEventHandler Progressed;
23+ public event EventHandler Complete;
2124
22- public void Execute(IEnumerable<string> files)
25+ public async void ExecuteAsync(IEnumerable<string> files,CancellationToken cancelToken)
2326 {
2427 foreach (string file in files)
2528 {
@@ -27,17 +30,27 @@ namespace CompleteEraser
2730
2831 try
2932 {
30- FileBreaker.BreakFileOrFolder(file);
33+ await Task.Factory.StartNew(() =>
34+ {
35+ FileBreaker.BreakFileOrFolder(file);
36+ }, cancelToken);
3137 }
32- catch(IOException){
38+ catch (OperationCanceledException)
39+ {
40+ return;
41+ }
42+ catch (IOException)
43+ {
3344 //ゴミ箱の中にフォルダーがあるとIOErrorがでるので握りつぶす
3445 }
3546
36- Progressed(this, new ProgressedEventArgs(file,null));
47+ Progressed(this, new ProgressedEventArgs(file, null));
3748 }
3849
3950 Progressing(this, new ProgressingEventArgs(null));
4051 SHEmptyRecycleBin(IntPtr.Zero, "", SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI);
52+
53+ this.Complete(this, null);
4154 }
4255 }
4356 }
--- a/CompleteEraser/IOperation.cs
+++ b/CompleteEraser/IOperation.cs
@@ -1,5 +1,6 @@
11 using System;
22 using System.Collections.Generic;
3+using System.Threading;
34
45 namespace CompleteEraser
56 {
@@ -33,6 +34,7 @@ namespace CompleteEraser
3334 {
3435 event ProgressingEventHandler Progressing;
3536 event ProgressedEventHandler Progressed;
36- void Execute(IEnumerable<string> targets);
37+ event EventHandler Complete;
38+ void ExecuteAsync(IEnumerable<string> targets, CancellationToken cancelToken);
3739 }
3840 }
--- a/CompleteEraser/MainForm.cs
+++ b/CompleteEraser/MainForm.cs
@@ -51,6 +51,12 @@ namespace CompleteEraser
5151 this.progressBar1.Maximum = this.files.Count();
5252 this.op.Progressing += new ProgressingEventHandler(op_Progressing);
5353 this.op.Progressed += new ProgressedEventHandler(op_Progressed);
54+ this.op.Complete += op_Complete;
55+ }
56+
57+ void op_Complete(object sender, EventArgs e)
58+ {
59+ this.Close();
5460 }
5561
5662 private void MainForm_Shown(object sender, EventArgs e)
@@ -63,40 +69,23 @@ namespace CompleteEraser
6369
6470 this.tokenSource = new CancellationTokenSource();
6571
66- this.task = new Task(() =>
67- {
68- op.Execute(this.files);
69- });
70- this.task.ContinueWith((t) =>
71- {
72- this.BeginInvoke(new Action(() =>
73- {
74- this.Close();
75- }));
76- });
77- this.task.Start();
72+ op.ExecuteAsync(this.files,this.tokenSource.Token);
7873 }
7974
8075 void op_Progressing(object sender, ProgressingEventArgs e)
8176 {
82- this.BeginInvoke(new Action(() =>
83- {
84- if (e.fileName == null)
85- this.label2.Text = Resources.FINAL_PROCESS;
86- else
87- this.label2.Text = string.Format(Resources.FILE_PROCESS, this.TrimFullPath(e.fileName));
88- }));
77+ if (e.fileName == null)
78+ this.label2.Text = Resources.FINAL_PROCESS;
79+ else
80+ this.label2.Text = string.Format(Resources.FILE_PROCESS, this.TrimFullPath(e.fileName));
8981 }
9082
9183 void op_Progressed(object sender, ProgressedEventArgs e)
9284 {
93- CancellationToken token = this.tokenSource.Token;
94- if (token.IsCancellationRequested)
95- token.ThrowIfCancellationRequested();
96-
9785 if (e.ex == null)
9886 {
99- this.BeginInvoke(new Action(() => { if (this.progressBar1.Value < this.progressBar1.Maximum) this.progressBar1.Value++; }));
87+ if (this.progressBar1.Value < this.progressBar1.Maximum)
88+ this.progressBar1.Value++;
10089 }else if(e.ex is IOException){
10190 DialogResult result = MessageBox.Show(e.ex.Message, "", MessageBoxButtons.AbortRetryIgnore);
10291 switch (result)
@@ -116,6 +105,8 @@ namespace CompleteEraser
116105 ProcessStartInfo info = new ProcessStartInfo(Application.ExecutablePath);
117106 info.Verb = "runas";
118107 info.UseShellExecute = true;
108+ if (this.info == null)
109+ info.Arguments = string.Join(" ", this.files);
119110 Process.Start(info);
120111 this.Hide();
121112 Thread.Sleep(1000);
--- a/CompleteEraser/Properties/AssemblyInfo.cs
+++ b/CompleteEraser/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
3232 // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
3333 // 既定値にすることができます:
3434 // [assembly: AssemblyVersion("1.0.*")]
35-[assembly: AssemblyVersion("1.17.0.0")]
36-[assembly: AssemblyFileVersion("1.17.0.0")]
35+[assembly: AssemblyVersion("1.18.0.0")]
36+[assembly: AssemblyFileVersion("1.18.0.0")]
--- a/CompleteEraser/ShrredFiles.cs
+++ b/CompleteEraser/ShrredFiles.cs
@@ -1,6 +1,8 @@
11 using System;
22 using System.Collections.Generic;
33 using System.IO;
4+using System.Threading;
5+using System.Threading.Tasks;
46
57 namespace CompleteEraser
68 {
@@ -8,19 +10,27 @@ namespace CompleteEraser
810 {
911 public event ProgressingEventHandler Progressing;
1012 public event ProgressedEventHandler Progressed;
13+ public event EventHandler Complete;
1114
12- public void Execute(IEnumerable<string> files)
15+ public async void ExecuteAsync(IEnumerable<string> files, CancellationToken cancelToken)
1316 {
1417 foreach (string file in files)
1518 {
16- Progressing(this,new ProgressingEventArgs(file));
19+ Progressing(this, new ProgressingEventArgs(file));
1720
1821 RETRY:
19- ProgressedEventArgs e = new ProgressedEventArgs(file,null);
22+ ProgressedEventArgs e = new ProgressedEventArgs(file, null);
2023
2124 try
2225 {
23- FileBreaker.BreakFileOrFolder(file);
26+ await Task.Factory.StartNew(() =>
27+ {
28+ FileBreaker.BreakFileOrFolder(file);
29+ }, cancelToken);
30+ }
31+ catch (OperationCanceledException)
32+ {
33+ break;
2434 }
2535 catch (UnauthorizedAccessException uae)
2636 {
@@ -36,6 +46,7 @@ namespace CompleteEraser
3646 if (e.breaked)
3747 break;
3848 }
49+ this.Complete(this, null);
3950 }
4051 }
4152 }
Show on old repository browser