private async void Button_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.SaveFileDialog save_dialog = new System.Windows.Forms.SaveFileDialog(); save_dialog.Filter = String.Format("{0} file (*{0})|*{0}|All files (*.*)|*.*", System.IO.Path.GetExtension(_fileAdress)); save_dialog.FilterIndex = 1; save_dialog.RestoreDirectory = true; if (save_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { RaiseDownloadStartedEvent(); IsDownloading = true; await Task.Run(() => { using (var stream = save_dialog.OpenFile()) { byte[] buffer; try { while ((buffer = _server.DownloadData(_fileAdress, 5000)) != null) { stream.Write(buffer, 0, buffer.Length); } } catch (FaultException <ExceptionType> fault) { if (fault.Detail == ExceptionType.ErrorDuringDataTransfer) { System.Windows.Forms.MessageBox.Show("Error accured during downloading. Please, try again"); } if (fault.Detail == ExceptionType.FileNotFound) { System.Windows.Forms.MessageBox.Show("File Not Found on server. Incorrect data link"); } } } }); RaiseDownloadEndedEvent(); IsDownloading = false; } }