OSDN Git Service

デットロックする可能性がある個所を修正した
authorkonekoneko <jbh03215@gmail.com>
Thu, 9 Feb 2012 09:38:57 +0000 (18:38 +0900)
committerkonekoneko <jbh03215@gmail.com>
Thu, 9 Feb 2012 09:38:57 +0000 (18:38 +0900)
CompleteEraser/MainForm.cs

index 4de7a8e..5d6bcdc 100644 (file)
@@ -32,7 +32,6 @@ namespace CompleteEraser
                 {\r
                     this.info = new SharedInfo();\r
                     this.files = this.info;\r
-                    this.progressBar1.Maximum = this.files.Count();\r
                     this.op = new ShrredFiles();\r
                 }\r
                 catch (IOException)\r
@@ -49,6 +48,7 @@ namespace CompleteEraser
                 this.op = new ShrredFiles();\r
                 this.files = args;\r
             }\r
+            this.progressBar1.Maximum = this.files.Count();\r
             this.op.Progressing += new ProgressingEventHandler(op_Progressing);\r
             this.op.Progressed += new ProgressedEventHandler(op_Progressed);\r
         }\r
@@ -63,23 +63,23 @@ namespace CompleteEraser
 \r
             this.tokenSource = new CancellationTokenSource();\r
 \r
-            this.progressBar1.Maximum = 1000;\r
-            this.task = Task.Factory.StartNew(() =>\r
+            this.task = new Task(() =>\r
             {\r
                 op.Execute(this.files);\r
             });\r
             this.task.ContinueWith((t) =>\r
             {\r
-                this.Invoke(new Action(() =>\r
+                this.BeginInvoke(new Action(() =>\r
                 {\r
                     this.Close();\r
                 }));\r
             });\r
+            this.task.Start();\r
         }\r
 \r
         void  op_Progressing(object sender, ProgressingEventArgs e)\r
         {\r
-            this.Invoke(new Action(() =>\r
+            this.BeginInvoke(new Action(() =>\r
             {\r
                 if (e.fileName == null)\r
                     this.label2.Text = Resources.FINAL_PROCESS;\r
@@ -96,7 +96,7 @@ namespace CompleteEraser
 \r
             if (e.ex == null)\r
             {\r
-                this.Invoke(new Action(() => { if (this.progressBar1.Value < this.progressBar1.Maximum) this.progressBar1.Value++; }));\r
+                this.BeginInvoke(new Action(() => { if (this.progressBar1.Value < this.progressBar1.Maximum) this.progressBar1.Value++; }));\r
             }else if(e.ex is IOException){\r
                 DialogResult result = MessageBox.Show(e.ex.Message, "", MessageBoxButtons.AbortRetryIgnore);\r
                 switch (result)\r