Click here to Skip to main content
15,889,877 members
Home / Discussions / C#
   

C#

 
GeneralRe: generate a sequence of number prefixed with a character Pin
Jimmy-IN8-Apr-15 23:35
Jimmy-IN8-Apr-15 23:35 
GeneralRe: generate a sequence of number prefixed with a character Pin
Eddy Vluggen9-Apr-15 0:23
professionalEddy Vluggen9-Apr-15 0:23 
AnswerRe: generate a sequence of number prefixed with a character Pin
V.9-Apr-15 2:08
professionalV.9-Apr-15 2:08 
QuestionGet listbox text to show in richtextbox + custom text Pin
Googooli868-Apr-15 22:52
Googooli868-Apr-15 22:52 
Answer[REPOST] Pin
Sascha Lefèvre8-Apr-15 23:35
professionalSascha Lefèvre8-Apr-15 23:35 
QuestionHow do I filter PPID between oPsType.PPIDFrom and oPsType.PPIDTo, and pay_type in oPsType.PAY_TYPE Pin
Member 115045458-Apr-15 9:42
Member 115045458-Apr-15 9:42 
AnswerRe: How do I filter PPID between oPsType.PPIDFrom and oPsType.PPIDTo, and pay_type in oPsType.PAY_TYPE Pin
Mycroft Holmes8-Apr-15 14:19
professionalMycroft Holmes8-Apr-15 14:19 
QuestionToday's Async Question #2 Pin
Kevin Marois8-Apr-15 8:35
professionalKevin Marois8-Apr-15 8:35 
1) DownloadProgress event handler is only called once at the start of the download and never again afterwards.

2) DownloadFileCompleted is called right away, even though the file has not yet completed.
private async Task downloadFileAsync(FileEntity file)
{
    try
    {
        using (WebClient client = new WebClient())
        {
            string outputFile = string.Format("{0}{1}", downloadPath, Path.GetFileName(file.FileName));

            if (File.Exists(outputFile))
            {
                File.Delete(outputFile);
            }

            client.DownloadProgressChanged += DownloadProgress(file);
            client.DownloadFileCompleted += DownloadFileCompleted(file);

            await client.DownloadFileTaskAsync(new Uri(file.FileName), outputFile);
        }
    }
    catch (Exception)
    {
        throw;
    }
}

DownloadProgressChangedEventHandler DownloadProgress(FileEntity file)
{
    Action<object, DownloadProgressChangedEventArgs> action = (sender, e) =>
    {
        double bytesIn = double.Parse(e.BytesReceived.ToString());
        double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
        double percentage = bytesIn / totalBytes * 100;

        var _filename = file.FileName;
    };

    return new DownloadProgressChangedEventHandler(action);
}

public AsyncCompletedEventHandler DownloadFileCompleted(FileEntity file)
{
    Action<object, AsyncCompletedEventArgs> action = (sender, e) =>
    {
        var _filename = file.FileName;
    };
    return new AsyncCompletedEventHandler(action);
}

I created these two event handlers because I'd like to know the name of the file in the events.

What am I doing wrong? Is there a better way to do these two?

Thanks
If it's not broken, fix it until it is

QuestionAnother Async Question Pin
Kevin Marois8-Apr-15 8:18
professionalKevin Marois8-Apr-15 8:18 
AnswerRe: Another Async Question PinPopular
Richard Deeming8-Apr-15 8:27
mveRichard Deeming8-Apr-15 8:27 
GeneralRe: Another Async Question Pin
Kevin Marois8-Apr-15 8:30
professionalKevin Marois8-Apr-15 8:30 
GeneralRe: Another Async Question Pin
Mycroft Holmes8-Apr-15 14:22
professionalMycroft Holmes8-Apr-15 14:22 
Question{0} Pin
Member 115906308-Apr-15 3:04
Member 115906308-Apr-15 3:04 
AnswerRe: {0} Pin
harold aptroot8-Apr-15 3:35
harold aptroot8-Apr-15 3:35 
AnswerRe: {0} Pin
Sascha Lefèvre8-Apr-15 3:49
professionalSascha Lefèvre8-Apr-15 3:49 
Questionconverting given hex value into rgb Pin
Member 115353748-Apr-15 1:25
Member 115353748-Apr-15 1:25 
GeneralRe: converting given hex value into rgb Pin
harold aptroot8-Apr-15 1:44
harold aptroot8-Apr-15 1:44 
AnswerRe: converting given hex value into rgb Pin
OriginalGriff8-Apr-15 4:38
mveOriginalGriff8-Apr-15 4:38 
JokeRe: converting given hex value into rgb Pin
Richard Deeming8-Apr-15 8:04
mveRichard Deeming8-Apr-15 8:04 
GeneralRe: converting given hex value into rgb Pin
OriginalGriff8-Apr-15 8:17
mveOriginalGriff8-Apr-15 8:17 
Questionsharing files on single pc in .net Pin
Member 115353748-Apr-15 1:23
Member 115353748-Apr-15 1:23 
QuestionRe: sharing files on single pc in .net Pin
Richard MacCutchan8-Apr-15 2:41
mveRichard MacCutchan8-Apr-15 2:41 
AnswerRe: sharing files on single pc in .net Pin
User 418025417-Jul-15 9:54
User 418025417-Jul-15 9:54 
Questioncode for androide xml analyser Pin
Member 115824057-Apr-15 22:29
Member 115824057-Apr-15 22:29 
QuestionRe: code for androide xml analyser Pin
Stefto7-Apr-15 22:56
professionalStefto7-Apr-15 22:56 

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.