public static void Output(BackgroundWorker sender, ImageGrid g, string id_, string path) { ImageTile it = imageTiles[id_]; DateTime time = DateTime.Now; MainWindow.Log("Saving Image (" + it.worldX + " " + it.worldY + ")"); time = DateTime.Now; { for (int i = 0; i < MainWindow.classesList.Count; i += 4) { Classes c0 = MainWindow.classesList[i]; Classes c1 = i + 1 < MainWindow.classesList.Count ? MainWindow.classesList[i + 1] : null; Classes c2 = i + 2 < MainWindow.classesList.Count ? MainWindow.classesList[i + 2] : null; Classes c3 = i + 3 < MainWindow.classesList.Count ? MainWindow.classesList[i + 3] : null; string classesNames = c0.className.Replace(' ', '_'); classesNames += c1 != null?c1.className.Replace(' ', '_') : ""; classesNames += c2 != null?c2.className.Replace(' ', '_') : ""; classesNames += c3 != null?c3.className.Replace(' ', '_') : ""; string filename = path + "\\" + (it.worldY) + "_" + (it.worldX) + "_" + classesNames + ".png"; MainWindow.dispatcher.Invoke(() => { ImageHelper.ExportClassification(it.id, c0, c1, c2, c3, filename, ref Stitch, i / 4, ref StichLock); }); } } MainWindow.dispatcher.Invoke(() => g.RemoveTile(it.tileX, it.tileY) ); float t = (float)(DateTime.Now - time).TotalSeconds; averageOutputTime = (averageOutputTime * outputDone + t) / (outputDone + 1); outputDone++; ReportProgress(sender); MainWindow.Log("Image (" + it.worldX + " " + it.worldY + ") saved in " + t + "s. Done"); GC.Collect(); }