diff options
author | emkael <emkael@tlen.pl> | 2012-11-16 14:12:04 +0000 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2012-11-16 14:12:04 +0000 |
commit | 876413f71c28b764340da760afa497474db3e917 (patch) | |
tree | 07179429f6353aeee6b4561abaf262bcaf489c97 | |
parent | 56424f1757660eadb1ea74ebae17a6cce84d5a05 (diff) |
* thread-safe result logging
git-svn-id: https://svn.emkael.info/an9k@14 05ec0d5d-773b-4d93-9e23-c81a7ac79feb
-rw-r--r-- | Analizator9000/Analizator9000/Accumulator.cs | 21 |
1 files 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<String> deals;
private Form1 form;
private Dictionary<int, List<int>> contracts;
- private StreamWriter outputFile;
+ private TextWriter outputFile;
private String filename;
public Accumulator(String[] deals, List<Contract> 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
{
|