Exemplo n.º 1
0
        /// <summary>
        /// Fired when user clicks submit button
        /// </summary>
        /// <param name="sender">Button</param>
        /// <param name="e">Event args</param>
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (DownloadedString != null)
            {
                FileDownloadingData.FileName = FileName.Text;
                if (Validate())
                {
                    FileNameProvided.Invoke(FileDownloadingData.FileName, DownloadedString);
                }

                return;
            }
            FileDownloadingData.Url = WebsiteUrl.Text;
            if (Validate())
            {
                await Task.Run(async() =>
                {
                    var webClient        = new WebClient();
                    var downloadedString = await webClient.DownloadStringTaskAsync(FileDownloadingData.Url);


                    StringDownloaded.Invoke(downloadedString);
                });
            }
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (DownloadedString != null)
            {
                FileNameProvided.Invoke(FileName.Text, DownloadedString);
                return;
            }

            DisplayText.Text = WebsiteUrl.Text;

            var currentUrl = WebsiteUrl.Text;

            await Task.Run(async() =>
            {
                var webClient        = new WebClient();
                var downloadedString = await webClient.DownloadStringTaskAsync(currentUrl);
                Thread.Sleep(2000);

                StringDownloaded.Invoke(downloadedString);
            });
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (DownloadedString != null)
            {
                FileNameProvided.Invoke(FileName.Text, DownloadedString);
                return;
            }

            var currentUrl = WebsiteUrl.Text;

            await Task.Run(async() =>
            {
                var webClient        = new WebClient();
                var downloadedString = await webClient.DownloadStringTaskAsync(currentUrl);

                Application.Current.Dispatcher.Invoke(() =>
                {
                    DisplayText.Text = "Success!";
                });
                StringDownloader.Invoke(downloadedString);
            });
        }