private async void StartSending() { cts = new CancellationTokenSource(); var progressIndicator = new Progress <double>(ReportProgress); try { this.sft = this.server.StartSending(this.FilePath, this.SelectedClient); } catch (SocketException) { MessageBox.Show("The selected host is unavailable.", "Transfar", MessageBoxButton.OK, MessageBoxImage.Stop, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); this.Close(); return; } this.originalLength = this.sft.FileLength; // If there are no issues with the transfer I can show the window fileInfo.Text = "Sending file " + this.sft.Name + " to " + this.sft.HostName + "..."; this.Show(); this.Activate(); try { await SendFileAsync(progressIndicator, cts.Token); } catch (Exception) { Console.WriteLine("Cancellation requested!"); } this.Close(); }
public ReceivingWindow(MainWindow mainWindow, MyClient client, TcpClient tcpClient) { this.client = client; this.tcpClient = tcpClient; this.sft = client.StartReceiving(tcpClient); InitializeComponent(); // if auto-accepting files is enabled if (Properties.Settings.Default.AutoAccept) { mainWindow.Ni.BalloonTipTitle = "MSFT"; mainWindow.Ni.BalloonTipText = "Receiving file " + this.sft.Name + " from " + this.sft.HostName; mainWindow.Ni.ShowBalloonTip(3000); this.Show(); this.Activate(); Yes_Button_Click(null, null); } else { fileInfo.Text = "Do you want to receive file " + this.sft.Name + " from " + this.sft.HostName + '?'; this.Show(); this.Activate(); } }