Click here to Skip to main content
15,887,585 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to enlarge the recording voice Pin
Star.jon27-Mar-13 23:05
Star.jon27-Mar-13 23:05 
GeneralRe: How to enlarge the recording voice Pin
Dave Kreskowiak28-Mar-13 2:00
mveDave Kreskowiak28-Mar-13 2:00 
Questionerror in crystal reports Pin
User349027-Mar-13 13:36
User349027-Mar-13 13:36 
AnswerRe: error in crystal reports Pin
Abhinav S27-Mar-13 17:58
Abhinav S27-Mar-13 17:58 
AnswerRe: error in crystal reports Pin
V.27-Mar-13 22:21
professionalV.27-Mar-13 22:21 
GeneralRe: error in crystal reports Pin
User349028-Mar-13 7:49
User349028-Mar-13 7:49 
GeneralRe: error in crystal reports Pin
V.28-Mar-13 8:19
professionalV.28-Mar-13 8:19 
QuestionHow to Async download multiple files using webclient simultaneously? Pin
Tridip Bhattacharjee27-Mar-13 8:01
professionalTridip Bhattacharjee27-Mar-13 8:01 
i want to download multiple file and want to show multiple progress bar for each file download progress.i got a code which can download file at a time but i want to start download many files at a time and also like to show progress bar for each file progress

suppose i have one textbox where i will put url and when i click on download button then download will start and a progress bar will be show for showing that file download progress. the same if i put another url in textbox and click on download button then another file download start and another progress bar will be shown to show that file download progress. i want that each file will be downloading in separate thread means my program will be multi threaded.

the code i have for downloading one file at a time.please guide me what to change in code to achieve my goal. thanks

C#
private Queue<string> _downloadUrls = new Queue<string>();

    private void downloadFile(IEnumerable<string> urls)
    {
        foreach (var url in urls)
        {
            _downloadUrls.Enqueue(url);
        }

        // Starts the download
        btnGetDownload.Text = "Downloading...";
        btnGetDownload.Enabled = false;
        progressBar1.Visible = true;
        lblFileName.Visible = true;

        DownloadFile();
    }

    private void DownloadFile()
    {
        if (_downloadUrls.Any())
        {
            WebClient client = new WebClient();
            client.DownloadProgressChanged += client_DownloadProgressChanged;
            client.DownloadFileCompleted += client_DownloadFileCompleted;

            var url = _downloadUrls.Dequeue();
            string FileName = url.Substring(url.LastIndexOf("/") + 1,
                        (url.Length - url.LastIndexOf("/") - 1));

            client.DownloadFileAsync(new Uri(url), "C:\\Test4\\" + FileName);
            lblFileName.Text = url;
            return;
        }

        // End of the download
        btnGetDownload.Text = "Download Complete";
    }

    private void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
    {
        if (e.Error != null)
        {
            // handle error scenario
            throw e.Error;
        }
        if (e.Cancelled)
        {
            // handle cancelled scenario
        }
        DownloadFile();
    }

    void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        double bytesIn = double.Parse(e.BytesReceived.ToString());
        double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
        double percentage = bytesIn / totalBytes * 100;
        progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
    }

tbhattacharjee

QuestionScreenshots -> Video file Pin
ADASD33333227-Mar-13 4:06
ADASD33333227-Mar-13 4:06 
AnswerRe: Screenshots -> Video file Pin
Abhinav S29-Mar-13 4:00
Abhinav S29-Mar-13 4:00 
QuestionSaving Screensaver in C# Pin
greylakota27-Mar-13 3:34
greylakota27-Mar-13 3:34 
QuestionRe: Saving Screensaver in C# Pin
Richard MacCutchan27-Mar-13 3:56
mveRichard MacCutchan27-Mar-13 3:56 
AnswerRe: Saving Screensaver in C# Pin
Dave Kreskowiak27-Mar-13 4:05
mveDave Kreskowiak27-Mar-13 4:05 
GeneralRe: Saving Screensaver in C# Pin
Richard MacCutchan27-Mar-13 5:04
mveRichard MacCutchan27-Mar-13 5:04 
QuestionC# progress failed! Pin
ccahe27-Mar-13 2:37
ccahe27-Mar-13 2:37 
AnswerRe: C# progress failed! Pin
Dave Kreskowiak27-Mar-13 4:02
mveDave Kreskowiak27-Mar-13 4:02 
AnswerRe: C# progress failed! Pin
ccahe27-Mar-13 22:02
ccahe27-Mar-13 22:02 
Questionsettings file in relaunching the application Pin
KRISHNARAYALU27-Mar-13 1:24
KRISHNARAYALU27-Mar-13 1:24 
AnswerRe: settings file in relaunching the application Pin
Richard MacCutchan27-Mar-13 3:53
mveRichard MacCutchan27-Mar-13 3:53 
GeneralRe: settings file in relaunching the application Pin
KRISHNARAYALU27-Mar-13 7:39
KRISHNARAYALU27-Mar-13 7:39 
GeneralRe: settings file in relaunching the application Pin
Richard MacCutchan27-Mar-13 7:46
mveRichard MacCutchan27-Mar-13 7:46 
GeneralRe: settings file in relaunching the application Pin
KRISHNARAYALU27-Mar-13 17:05
KRISHNARAYALU27-Mar-13 17:05 
GeneralRe: settings file in relaunching the application Pin
Richard MacCutchan27-Mar-13 23:58
mveRichard MacCutchan27-Mar-13 23:58 
QuestionC# Convertion Pin
Midnight Ahri26-Mar-13 17:20
Midnight Ahri26-Mar-13 17:20 
AnswerRe: C# Convertion PinPopular
parths26-Mar-13 21:08
parths26-Mar-13 21:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.