When you click the "specify" button, the path to the folder with files is indicated, a list of files is obtained and loaded once more into the picturebox and in parallel in the asynchronous method, some data is generated from the image, and after generating them, the second button becomes available. The question is how to write the result of the asynchronous method in the variable Data?
public string[] Images; public string[] Data; public int count = 0; private static readonly HttpClient client = new HttpClient(new HttpClientHandler { AllowAutoRedirect = true, UseCookies = true, CookieContainer = new CookieContainer() }); public void LoadImage() { Image CurrentImage = Image.FromFile(Images[this.count]); pictureBox1.Image = CurrentImage; LoadJSONAsync(CurrentImage); } public async void LoadJSONAsync(Image Image) { /* GET LINE */ string Line = "LINE"; //Нужно записать результат асинхронного вызова в переменную класса Data this.Data[this.count] = Line; button2.Enabled = true; } private void button1_Click(object sender, EventArgs e) { if(folderBrowserDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = folderBrowserDialog1.SelectedPath; Images = Directory.GetFiles(textBox1.Text); this.count = 0; LoadImage(); } } private void button2_Click(object sender, EventArgs e) { //Работа с this.Data[this.count] } 