protected override void ProcessSolvePartialProblemsMessage(SolvePartialProblemsMessage message) { var partialProblemsHelper = new PartialProblemsHelper(message); foreach (var partialProblem in partialProblemsHelper.Problems) { var thread = new IOThread() { TaskId = partialProblem.TaskId, ProblemInstanceId = message.Id, ProblemType = message.ProblemType, State = EState.Busy, RealThread = new Thread(() => SolvePartialProblem(partialProblemsHelper, partialProblem)) }; _runningThreads.Add(thread); thread.RealThread.Start(); } }
private void SolvePartialProblem(PartialProblemsHelper partialProblemsHelper, PartialProblem partialProblem) { var taskSolver = GetProperTaskSolver(partialProblemsHelper.ProblemType, partialProblem.Data); byte[] solution = taskSolver.Solve(partialProblem.Data, new TimeSpan(100000, 0, 0, 0)); //TODO: Ogarnac te timeouty bool dziaa = false; IOThread thread = null; while (!dziaa) { try { thread = _runningThreads.FirstOrDefault(x => x.TaskId == partialProblem.TaskId); thread.State = EState.Idle; dziaa = true; } catch (Exception) { } } partialProblemsHelper.Solutions.Add(new Solution(partialProblem.TaskId, false, ESolutionType.Partial, thread.HowLong, solution)); //TODO: Ogarnac te timeouty też if (partialProblemsHelper.Solutions.Count == partialProblemsHelper.Problems.Count) //Wszystkie rozwiazania policzone { SolutionsMessage solutionsMessage = new SolutionsMessage(partialProblemsHelper.ProblemType, partialProblemsHelper.ProblemId, partialProblemsHelper.Message.CommonData, partialProblemsHelper.Solutions); SendMessage(solutionsMessage.Serialize()); } lock (_runningThreadsLockObject) { _runningThreads.Remove(thread); } }