private static void UpdateMaps() { while (!Globals.ClosingEditor) { if (Globals.MapsToScreenshot.Count > 0 && Globals.FetchingMapPreviews == false && sMyForm.InvokeRequired) { if (sProgressForm == null || sProgressForm.IsDisposed || sProgressForm.Visible == false) { sProgressForm = new FrmProgress(); sProgressForm.SetTitle(Strings.MapCacheProgress.title); new Task(() => Globals.MainForm.ShowDialogForm(sProgressForm)).Start(); while (Globals.MapsToScreenshot.Count > 0) { try { var maps = MapInstance.Lookup.ValueList.ToArray(); foreach (MapInstance map in maps) { if (!sMyForm.Disposing && sProgressForm.IsHandleCreated) { sProgressForm.BeginInvoke( (Action)(() => sProgressForm.SetProgress( Strings.MapCacheProgress.remaining.ToString( Globals.MapsToScreenshot.Count ), -1, false )) ); } if (map != null) { map.Update(); } Networking.Network.Update(); Application.DoEvents(); } } catch (Exception ex) { Logging.Log.Error( ex, "JC's Solution for UpdateMaps collection was modified bug did not work!" ); } Thread.Sleep(50); } Globals.MapGrid.ResetForm(); while (!sProgressForm.IsHandleCreated) { Thread.Sleep(50); } sProgressForm.BeginInvoke(new Action(() => sProgressForm.Close())); } } Thread.Sleep(100); } }