private void worker_DoWork(object sender, DoWorkEventArgs e) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); //loop here for (int i = 0; i < maxIterasi; i++) { if (worker.CancellationPending) { e.Cancel = true; break; } float[] fitness = genetik.HitungFitness(); genetik.Seleksi(fitness); genetik.StartCrossOver(); float[] fitnessAfterMutation = genetik.Mutasi(); for (var j = 0; j < fitnessAfterMutation.Length; j++) { if (ClassHelper.AlmostEquals(fitnessAfterMutation[j], 1.0, 0)) { jadwal_kuliah = genetik.GetIndividu(j); UpdateUI(i, maxIterasi, fitnessAfterMutation, true); stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; MessageBox.Show(string.Format("Solusi ditemukan\n" + "Waktu yang diperlukan: " + "{0:00} Jam, {1:00} Menit,\n{2:00} Detik dan {3:00} Milidetik\n" + "Report disimpan di report.xls", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10), "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); Export2Excel(); genetik.WriteLog2Disk(); return; } } //genetik.WriteLog2Disk(); UpdateUI(i, maxIterasi, fitnessAfterMutation, false); } //end loop here MessageBox.Show("Solusi TIDAK ditemukan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Warning); //save last log genetik.WriteLog2Disk(); }