private void testButton_Click(object sender, System.EventArgs e) { // Einige Dateien parallel asynchron herunterladen try { FileStream fs1 = new FileStream(Path.Combine(Path.GetTempPath(), "Test1.pdf"), FileMode.Create, FileAccess.Write); WebDownload webDownload = new WebDownload(); webDownload.DownloadAsync(this.urlTextBox.Text, fs1, 1024, new WebDownload.DownloadProgress(this.DownloadProgressHandler), null); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } try { FileStream fs2 = new FileStream(Path.Combine(Path.GetTempPath(), "Test2.pdf"), FileMode.Create, FileAccess.Write); WebDownload webDownload = new WebDownload(); webDownload.DownloadAsync(this.urlTextBox.Text, fs2, 1024, new WebDownload.DownloadProgress(this.DownloadProgressHandler), null); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/* Methode für den Schalter zum asynchronen Download */ private void asyncDownloadAsFile_Click(object sender, System.EventArgs e) { FileStream fileStream = null; try { // FileStream für die Datei erzeugen fileStream = new FileStream(this.destFileNameTextBox.Text, FileMode.Create, FileAccess.Write); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); // FileStream schließen try { fileStream.Close(); } catch {} return; } // Datei asynchron herunterladen WebDownload webDownload = new WebDownload(); webDownload.DownloadAsync(this.urlTextBox.Text, fileStream, 1024, new WebDownload.DownloadProgress(this.DownloadProgressHandler), new WebDownload.DownloadEnd(this.DownloadEndHandler)); }