public void LoadWorld(string filename)
{
_loadTimer.Reset();
_loadTimer.Start();
_saveTimer.Stop();
CurrentFile = filename;
CurrentWorld = null;
GC.WaitForFullGCComplete();
Task.Factory.StartNew(() => World.LoadWorld(filename))
.ContinueWith(t => CurrentWorld = t.Result, TaskFactoryHelper.UiTaskScheduler)
.ContinueWith(t => RenderEntireWorld())
.ContinueWith(t =>
{
if (CurrentWorld != null)
{
PixelMap = t.Result;
UpdateTitle();
Points.Clear();
Points.Add("Spawn");
Points.Add("Dungeon");
foreach (NPC npc in CurrentWorld.NPCs)
{
Points.Add(npc.Name);
}
MinimapImage = RenderMiniMap.Render(CurrentWorld);
_loadTimer.Stop();
OnProgressChanged(this, new ProgressChangedEventArgs(0, string.Format("World loaded in {0} seconds.", _loadTimer.Elapsed.TotalSeconds)));
_saveTimer.Start();
}
_loadTimer.Stop();
}, TaskFactoryHelper.UiTaskScheduler);
}