private async void SaveAllEndButton_Click(object sender, RoutedEventArgs e) { var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog() { Description = "保存先フォルダを選択", }; folderBrowserDialog.ShowDialog(); var folder = folderBrowserDialog.SelectedPath; var saveFileWriter = new SaveFileWriter(folder); foreach (var std in StationReader.GetAllEnds()) { await saveFileWriter.SaveTrainData(std.StationId); } }
private async Task DataGeter(CancellationToken cancellationToken, IEnumerable <int> id, string saveFolderPath) { while (true) { var savePath = saveFolderPath + $"\\{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}"; Directory.CreateDirectory(savePath); var saveFileWriter = new SaveFileWriter(savePath); await Task.Run(() => { Parallel.ForEach(id, async staId => { try { await saveFileWriter.SaveTrainData(staId); if (staId < 5) { LogText.WriteLine($"{DateTime.Now}: 広域データID{staId}を保存しました..."); } else { LogText.WriteLine($"{DateTime.Now}: {StationReader.GetStationById(staId).Name}を保存しました..."); } } catch (TrainDataGetException ex) { LogText.WriteLine("通信中に例外が発生しました..."); throw; } }); }); LogText.WriteLine("取得プロセス一時停止(取得完了)..."); await Task.Delay(DelayTime * 60 * 1000, cancellationToken); if (cancellationToken.IsCancellationRequested) { break; } } }