/// <summary> /// Download file from cloud /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void button2_Click(object sender, EventArgs e) { if (this.listBox.SelectedIndex != -1) { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { try { string selectedFile = (string)listBox.SelectedItem; // Asinhrono se pozove metoda Task <Stream> task = Task.Run(() => csClient.DownloadFile(selectedFile)); Stream stream = await task; using (var fileStream = File.Create(System.IO.Path.Combine(fbd.SelectedPath, selectedFile))) { stream.CopyTo(fileStream); MessageBox.Show(String.Format("Fajl {0} je uspesno downloadovan.", selectedFile), "Cloud Download"); } } catch (Exception ex) { MessageBox.Show("Doslo je do greske pri downloadovanju."); } } } }