From 876413f71c28b764340da760afa497474db3e917 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 16 Nov 2012 14:12:04 +0000 Subject: * thread-safe result logging git-svn-id: https://svn.emkael.info/an9k@14 05ec0d5d-773b-4d93-9e23-c81a7ac79feb --- Analizator9000/Analizator9000/Accumulator.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Analizator9000/Analizator9000/Accumulator.cs b/Analizator9000/Analizator9000/Accumulator.cs index 303b718..c5e1bf2 100644 --- a/Analizator9000/Analizator9000/Accumulator.cs +++ b/Analizator9000/Analizator9000/Accumulator.cs @@ -14,7 +14,7 @@ namespace Analizator9000 private Stack deals; private Form1 form; private Dictionary> contracts; - private StreamWriter outputFile; + private TextWriter outputFile; private String filename; public Accumulator(String[] deals, List contracts, Form1 form) @@ -48,7 +48,7 @@ namespace Analizator9000 this.contracts[contract.Denomination].Add(contract.Declarer); } this.filename = Utils.getFilename("result"); - this.outputFile = new StreamWriter(@"files\"+this.filename); + this.outputFile = TextWriter.Synchronized(File.AppendText(@"files\"+this.filename)); } private int portionSize; @@ -89,11 +89,14 @@ namespace Analizator9000 try { BCalcResult result = solver.run(entry); - String line = "#" + result.dealNo + ", " + result.declarer + " gra w " + result.trumpSuit + ", lew: " + result.tricks; - this.update(result); - this.form.setResult(this.getString()); - this.form.addStatusLine(line); - this.outputFile.WriteLine(line); + if (!this.abort) + { + String line = "#" + result.dealNo + ", " + result.declarer + " gra w " + result.trumpSuit + ", lew: " + result.tricks; + this.update(result); + this.form.setResult(this.getString()); + this.form.addStatusLine(line); + this.outputFile.WriteLine(line); + } } catch (Exception ex) { @@ -131,11 +134,11 @@ namespace Analizator9000 this.threadsRunning--; this.analyzed++; this.form.setProgress((int)(100 * this.analyzed / this.toAnalyze)); - if (threadsRunning == 0) + if (threadsRunning < this.portionSize) { if (this.deals.Count > 0) { - this.run(); + this.run(1); } else { -- cgit v1.2.3