private async void Button_Click(object sender, RoutedEventArgs e) { if (toggleSw.IsOn) { if (jsonFolder is null) { await new Windows.UI.Popups.MessageDialog("Выберите папку для сохранения JSON файлов").ShowAsync(); FolderPicker folderPicker = new FolderPicker(); folderPicker.FileTypeFilter.Add("*"); jsonFolder = await folderPicker.PickSingleFolderAsync(); if (jsonFolder is null) { toggleSw.IsOn = false; return; } randomData = new RandomData(jsonFolder); randomData.AddSensor(GraphKeys.tempExt.ToString(), -20, 50, Const.defaultGraphValues[0]); randomData.AddSensor(GraphKeys.tempInt.ToString(), 10, 40, Const.defaultGraphValues[1]); randomData.AddSensor(GraphKeys.humidity.ToString(), 0, 100, Const.defaultGraphValues[2]); randomData.AddSensor(GraphKeys.pressure.ToString(), 730, 790, Const.defaultGraphValues[3]); randomData.AddSensor(GraphKeys.lighting.ToString(), 0, 200, Const.defaultGraphValues[4]); data = Data.Data.GetInstance(); data.Points = GetChartSeries() .Select(x => x.ToList()) .ToArray(); data.DataAdded += Data_DataAdded; var queryResult = jsonFolder.CreateFileQueryWithOptions( new QueryOptions(CommonFileQuery.DefaultQuery, new List <string>() { ".json" })); queryResult.ContentsChanged += QueryResult_ContentsChanged; var files = await queryResult.GetFilesAsync(); files.ForEach(async x => { try { await x.DeleteAsync(); } catch (FileNotFoundException) { } }); sensors = new Sensors(queryResult); devices = new Devices(); } randomData.Start(); } else { randomData?.Stop(); } }