summaryrefslogtreecommitdiff
path: root/Program.cs
diff options
context:
space:
mode:
authorMichał Klichowicz <emkael@tlen.pl>2023-11-05 14:16:25 +0100
committerMichał Klichowicz <emkael@tlen.pl>2023-11-05 14:16:25 +0100
commit86b5e6fab4f7d223d30f0b370020a6ba42cb8d05 (patch)
tree9c6a84ebe11e7ddff8e06bd665f3146821091f64 /Program.cs
parentbc32d973874ff5cd1d495395f9f8489e95b9bb0f (diff)
Refactoring separate files into separate threads
Diffstat (limited to 'Program.cs')
-rw-r--r--Program.cs74
1 files changed, 12 insertions, 62 deletions
diff --git a/Program.cs b/Program.cs
index 51394ff..aacf8e1 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
-using System.Text;
+using System.Threading;
using System.Windows.Forms;
using System.IO;
@@ -35,72 +35,22 @@ namespace BCDD
static void Main(string[] args)
{
List<String> files = Program.getFiles(args);
+ List<BCDDFile> workers = new List<BCDDFile>();
List<String> errors = new List<String>();
+ BCDDFile.filesCounter = files.Count;
if (files.Count > 0)
{
foreach (String filename in files)
{
- try
- {
- Console.WriteLine("Analyzing " + filename);
- PBNFile file = new PBNFile(filename);
- foreach (PBNBoard board in file.Boards)
- {
- DDTable table = new DDTable(board);
- String boardNo;
- try
- {
- boardNo = board.GetNumber();
- }
- catch (FieldNotFoundException)
- {
- boardNo = "?";
- }
- try
- {
- int[,] ddTable = table.GetDDTable();
- if (ddTable != null)
- {
- Console.WriteLine("Board " + boardNo);
- DDTable.PrintTable(ddTable);
- ParScore par = new ParScore(board);
- ParContract contract = par.GetParContract(ddTable);
- Console.WriteLine(contract);
- Console.WriteLine();
- board.SaveDDTable(ddTable);
- board.SaveParContract(contract);
- }
- else
- {
- String error = "unable to determine DD table for board " + boardNo;
- errors.Add(String.Format("[{0}] {1}", filename, error));
- Console.WriteLine("ERROR: " + error);
- }
- }
- catch (DllNotFoundException)
- {
- throw;
- }
- catch (Exception e)
- {
- errors.Add(String.Format("[{0}:{1}] {2}", filename, boardNo, e.Message));
- Console.WriteLine("ERROR: " + e.Message);
- }
- file.WriteBoard(board);
- }
- file.Save();
- }
- catch (DllNotFoundException e)
- {
- errors.Add("libbcalcdds.dll could not be loaded - make sure it's present in application directory!");
- Console.WriteLine("ERROR: " + e.Message);
- break;
- }
- catch (Exception e)
- {
- errors.Add(e.Message);
- Console.WriteLine("ERROR: " + e.Message);
- }
+ BCDDFile worker = new BCDDFile(filename);
+ workers.Add(worker);
+ Console.WriteLine("Analyzing " + filename);
+ ThreadPool.QueueUserWorkItem(new WaitCallback(worker.analyze));
+ }
+ BCDDFile.filesCountdown.WaitOne();
+ foreach (BCDDFile w in workers)
+ {
+ errors.AddRange(w.errors);
}
if (errors.Count > 0) {
Console.WriteLine("Following ERRORs occured:");