private static void scanAndAppend(string directory) { activeScannings++; Task.Factory.StartNew(() => getGamesInFolder(directory)).ContinueWith(games => { lock (games) { foreach (var game in games.Result) { var name = gameChecker.getDisplayName(game); if (!installedGames.ContainsKey(name)) { GameStartInfo t = new GameStartInfo(); t.location = game; if (game.Contains("steamapps")) { t.platform = GameStartInfo.Platform.Steam; } else { t.platform = GameStartInfo.Platform.Unknown; } installedGames.Add(name, t); } } } activeScannings--; }).ConfigureAwait(true); }
private void scanAndAppend(string directory) { activeScannings++; metroProgressBar1.ProgressBarStyle = ProgressBarStyle.Marquee; metroProgressBar1.MarqueeAnimationSpeed = 10; lblScanProgress.Text = $"scanning for games in {activeScannings} folder(s)"; lblScanProgress.Visible = true; this.Refresh(); Task.Factory.StartNew(() => getGamesInFolder(directory)).ContinueWith(games => { listBox1.Invoke(new Action(() => { foreach (var game in games.Result) { var name = gameChecker.getDisplayName(game); if (!listBox1.Items.Contains(name)) { GameStartInfo t = new GameStartInfo(); t.location = game; if (game.Contains("steamapps")) { t.platform = GameStartInfo.Platform.Steam; } else { t.platform = GameStartInfo.Platform.Unknown; } listBox1.Items.Add(name); installedGames.Add(name, t); } } })); activeScannings--; if (activeScannings == 0) { metroProgressBar1.Invoke(new Action(() => { metroProgressBar1.ProgressBarStyle = ProgressBarStyle.Continuous; metroProgressBar1.Value = 0; })); lblScanProgress.Invoke(new Action(() => { lblScanProgress.Text = $"finished!"; lblScanProgress.Visible = false; })); } else { lblScanProgress.Invoke(new Action(() => { lblScanProgress.Text = $"scanning for games in {activeScannings} folder(s)"; lblScanProgress.Visible = true; })); } }).ConfigureAwait(true); }