private void LoadSelectedLesson() { CodeProfiler.Start("LoadLesson"); Debug.WriteLine("Loading lesson: " + SelectedLesson); KillImageLoader(); string lessonPath = LessonBasePath + SelectedLesson; string[] files = Directory.GetFiles(lessonPath); Array.Sort(files); //Clean up old cards. Dispose Audio object. foreach (FlashCardItem ptrItem in Cards) { ptrItem.Dispose(); } Cards.Clear(); FlashCardItem newItem; //Load and sort cards. CodeProfiler.Start("Generate Items"); string CardName; string CardText; string CardImageType; foreach (string ptrFile in files) { //Card Format //[CardIndex]#<Card Name>.<Image type> CardImageType = Path.GetExtension(ptrFile).ToLower(); if (!IsImageTypeSupported(CardImageType)) { continue; } CardName = CardText = Path.GetFileNameWithoutExtension(ptrFile); if (CardName.Contains("#")) { CardText = CardName.Substring(CardName.IndexOf("#") + 1); } newItem = new FlashCardItem(CardName, CardText, ptrFile); Debug.WriteLine("> " + newItem.Text); Cards.Add(newItem); } CodeProfiler.Stop("Generate Items"); //Load card contents. if (UseThread) { //Use threading to load images. CardsLoader = new Thread(LoadCardsData); CardsLoader.Start(); CodeProfiler.Start("LoadCard1"); Cards[0].Load(); //Make sure first image is loaded CodeProfiler.Stop("LoadCard1"); } else { //Single thread operation (Slower) - Keep for debugging purpose foreach (FlashCardItem ptrItem in Cards) { CodeProfiler.Start("Load Card " + ptrItem.Name); ptrItem.Load(); CodeProfiler.Stop("Load Card " + ptrItem.Name); } } Cards.ResetIndex(); CardsLoader.Join(); OnLessonLoaded(); Debug.WriteLine("Lesson loaded."); CodeProfiler.Stop("LoadLesson"); }