private async void OnOptimization() { if (!User.IsDeveloper()) { return; } SelectedSetup.Online = true; SysManager.OptimizationSetup = SelectedSetup; await SysManager.OfflineTrading(SelectedSetup); try { await Task.Factory.StartNew(() => SysManager.GetData(SelectedSetup)).ContinueWith(async _ => { try { var ga = new GA(SysManager, UpdateProgress, 2, 0.8, 0.1, 100, 10, 0.0001); ga.InputGenes = SysManager.GetGenes(); await ga.Go(); double[] bestGenes; double bestFitness; ga.GetBest(out bestGenes, out bestFitness); var file = DateTime.Now.ToString("yyMMddHHmm") + ".csv"; File.WriteAllText(Roaming + @"\Otimização\" + file, Log); Log = TimeTag + "Resultado da otimização no ficheiro " + file + ". Pressione F4 para abrir sua localização.\r\n\r\n" + TimeTag + "Final/Best: " + bestFitness + "\r\n" + SysManager.SetGenes(bestGenes).ToString() + "\r\n" + Log; SysManager.OptimizationSetup.Online = false; SelectedSetup.Online = false; } catch (Exception ex) { SelectedSetup.Online = false; Log = TimeTag + ex.Message + "\r\n" + Log; var file = DateTime.Now.ToString("yyMMddHHmm") + ".csv"; File.WriteAllText(Roaming + @"\Otimização\" + file, Log); } }); } catch (Exception e) { SelectedSetup.Online = false; Log = TimeTag + e.Message + "\r\n" + Log; var file = DateTime.Now.ToString("yyMMddHHmm") + ".csv"; File.WriteAllText(Roaming + @"\Otimização\" + file, Log); } }