From 4ef50b1d961130eb86b5a0e10431b3847ff849eb Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 16 Nov 2012 20:37:03 +0000 Subject: * accumulator thread count fixed git-svn-id: https://svn.emkael.info/an9k@18 05ec0d5d-773b-4d93-9e23-c81a7ac79feb --- Analizator9000/Analizator9000/Accumulator.cs | 30 +++++++++++++--------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'Analizator9000') diff --git a/Analizator9000/Analizator9000/Accumulator.cs b/Analizator9000/Analizator9000/Accumulator.cs index c5e1bf2..64dde12 100644 --- a/Analizator9000/Analizator9000/Accumulator.cs +++ b/Analizator9000/Analizator9000/Accumulator.cs @@ -51,19 +51,20 @@ namespace Analizator9000 this.outputFile = TextWriter.Synchronized(File.AppendText(@"files\"+this.filename)); } - private int portionSize; - private int threadsRunning; + private int portionSize = 10; + private int threadsRunning = 0; public int run(int portionSize = 0) { - if (portionSize > 0) + if (portionSize == 0) { - this.portionSize = portionSize; + portionSize = this.portionSize; } - this.threadsRunning = Math.Min(this.portionSize, this.deals.Count); - for (int i = 0; i < this.threadsRunning; i++) + int toRun = Math.Min(portionSize, this.deals.Count); + for (int i = 0; i < toRun; i++) { Action worker = this.analyzeDeal; worker.BeginInvoke(this.deals.Pop(), this.endAnalyze, worker); + this.threadsRunning++; } return this.deals.Count; } @@ -134,18 +135,15 @@ namespace Analizator9000 this.threadsRunning--; this.analyzed++; this.form.setProgress((int)(100 * this.analyzed / this.toAnalyze)); + if (threadsRunning == 0 && this.deals.Count == 0) + { + this.form.setProgress(100); + this.form.addStatusLine("Analiza zakończona. Wyniki w pliku: " + this.filename); + finished = true; + } if (threadsRunning < this.portionSize) { - if (this.deals.Count > 0) - { - this.run(1); - } - else - { - this.form.setProgress(100); - this.form.addStatusLine("Analiza zakończona. Wyniki w pliku: " + this.filename); - finished = true; - } + this.run(1); } } if (finished) -- cgit v1.2.3