/// <summary> /// stops the cases queue worker /// </summary> public void StopRlmDbWorkersCases() { case_queue.CompleteAdding(); ctSourceCases.Cancel(); dbSavingTime.Stop(); RlmDbLogger.Info("\n" + string.Format("[{0:G}]: Data successfully saved to the database in {1}", DateTime.Now, dbSavingTime.Elapsed), Network.DatabaseName); if (ConfigFile.DropDb) { Task.Delay(5000).Wait(); rlmDb.DropDB(); RlmDbLogger.Info("\n" + string.Format("[{0:G}]: {1} database successfully dropped...\n*** END ***\n", DateTime.Now, Network.DatabaseName), Network.DatabaseName); } // notify parent network that db background workers are done DataPersistenceComplete?.Invoke(); progressUpdater.Stop(); foreach (var item in rlmDb.CaseWorkerQueues) { item.CompleteAdding(); } }
/// <summary> /// Save the new network and send it to a task. It also starts the database workers /// </summary> /// <param name="rnetwork"></param> /// <param name="io_types"></param> /// <param name="inputs"></param> /// <param name="outputs"></param> /// <param name="rnn_net"></param> public void NewNetwork(Rnetwork rnetwork, List <Input_Output_Type> io_types, List <Input> inputs, List <Output> outputs, IRlmNetwork rnn_net) { //todo: rnn dbmanager and save dbSavingTime.Start(); RlmDbLogger.Info("\n" + string.Format("[{0:G}]: Started saving data for {1}...", DateTime.Now, Network.DatabaseName), Network.DatabaseName); Task t1 = Task.Run(() => { rlmDb.SaveNetwork(rnetwork, io_types, inputs, outputs, rnn_net); }); t1.Wait(); StartRlmDbWorkers(); }
/// <summary> /// signals that training is done /// </summary> public void TrainingDone() { trainingDone = true; //background thread to stop session db workers when done Task.Factory.StartNew(() => { while (true) { bool processing = Sessions.Any(a => a.Value.CreatedToDb == false || a.Value.UpdatedToDb == false); if (!processing && /*Sessions.Count > 0 &&*/ trainingDone) { //StopRlmDbWorkersSessions(); sessionsDone = true; System.Diagnostics.Debug.WriteLine("Worker Session done"); break; } //Task.Delay(5 * 1000).Wait(); Thread.Sleep(5000); } }, TaskCreationOptions.LongRunning); //background thread to stop case db workers when done Task.Factory.StartNew(() => { while (true) { if (sessionsDone && //rlmDb.DistinctCaseSessionsCount() == totalSessionsCount && MASTER_CASE_QUEUE.Count == 1 && MASTER_CASE_QUEUE.ElementAt(0).Count == 0 && rlmDb.CaseWorkerQueues.All(a => a.WorkerQueues.Count == 0 && !a.IsBusy)) { // notify parent network that db background workers are done DataPersistenceComplete?.Invoke(); dbSavingTime.Stop(); RlmDbLogger.Info("\n" + string.Format("[{0:G}]: Data successfully saved to the database in {1}", DateTime.Now, dbSavingTime.Elapsed), Network.DatabaseName); System.Diagnostics.Debug.WriteLine("Worker Cases done"); break; } Thread.Sleep(5000); } }, TaskCreationOptions.LongRunning); }
/// <summary> /// stops the cases queue worker /// </summary> public void StopRlmDbWorkersCases() { bcCasesQueue?.CompleteAdding(); if (ConfigFile.DropDb) { Thread.Sleep(5000); rlmDb.DropDB(); RlmDbLogger.Info("\n" + string.Format("[{0:G}]: {1} database successfully dropped...\n*** END ***\n", DateTime.Now, Network.DatabaseName), Network.DatabaseName); } progressUpdater.Stop(); if (rlmDb.CaseWorkerQueues != null) { foreach (var item in rlmDb.CaseWorkerQueues) { item.WorkerQueues.CompleteAdding(); } } }