Click here to Skip to main content
15,893,663 members
Home / Discussions / C#
   

C#

 
GeneralRe: Named pipes: C# server, C++ client Pin
Crazy Joe Devola16-Feb-16 12:46
Crazy Joe Devola16-Feb-16 12:46 
AnswerRe: Named pipes: C# server, C++ client Pin
Crazy Joe Devola16-Feb-16 13:12
Crazy Joe Devola16-Feb-16 13:12 
GeneralRe: Named pipes: C# server, C++ client Pin
Richard Andrew x6416-Feb-16 13:15
professionalRichard Andrew x6416-Feb-16 13:15 
QuestionHow to read and print *.plt file by C# Pin
tienich15-Feb-16 22:01
tienich15-Feb-16 22:01 
AnswerRe: How to read and print *.plt file by C# Pin
Pete O'Hanlon15-Feb-16 22:32
mvePete O'Hanlon15-Feb-16 22:32 
QuestionCopy File From Server With Progress And Completion Pin
Kevin Marois15-Feb-16 18:42
professionalKevin Marois15-Feb-16 18:42 
AnswerRe: Copy File From Server With Progress And Completion Pin
Garth J Lancaster15-Feb-16 19:26
professionalGarth J Lancaster15-Feb-16 19:26 
AnswerRe: Copy File From Server With Progress And Completion Pin
Richard Deeming16-Feb-16 2:06
mveRichard Deeming16-Feb-16 2:06 
Your DownloadFile method looks off to me. Calling Task.Run just to await the result doesn't really achieve anything.

It would be cleaner to use Task.Yield to force the rest of the method to execute in the continuation.

You should also return a Task so that the calling method can wait for the transfers to complete.
Avoid async void methods - You've Been Haacked[^]

To pass the file names to the progress method, you just need to capture them in the progress callback.

C#
public async Task DownloadFile(string sourceFile, string destFile)
{
    await Task.Yield(); 
    await TransferFile(sourceFile, destFile);
    FileTransferComplete(sourceFile, destFile);
}

private async Task TransferFile(string sourceFile, string destFile)
{
    Action<double> reportProgress = percentage => FileTransferProgress(sourceFile, destFile, percentage);
    IProgress<double> progress = new Progress<double>(reportProgress);
    await FileEx.CopyAsync(sourceFile, destFile, progress);
}

private void FileTransferProgress(string sourceFile, string destFile, double percentage)
{
    // Report the progress
}

private void FileTransferComplete(string sourceFile, string destFile)
{
    // Transfer of a file has completed.
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Copy File From Server With Progress And Completion Pin
Kevin Marois16-Feb-16 3:38
professionalKevin Marois16-Feb-16 3:38 
AnswerRe: Copy File From Server With Progress And Completion Pin
Pete O'Hanlon16-Feb-16 2:10
mvePete O'Hanlon16-Feb-16 2:10 
GeneralRe: Copy File From Server With Progress And Completion Pin
Kevin Marois16-Feb-16 3:36
professionalKevin Marois16-Feb-16 3:36 
QuestionIcon on "Dekstop" Pin
Member 1224802815-Feb-16 12:01
Member 1224802815-Feb-16 12:01 
QuestionRe: Icon on "Dekstop" Pin
ZurdoDev15-Feb-16 13:55
professionalZurdoDev15-Feb-16 13:55 
AnswerRe: Icon on "Dekstop" Pin
Gerry Schmitz16-Feb-16 6:05
mveGerry Schmitz16-Feb-16 6:05 
Questionsingle submit button with multiple tabs Pin
Sandy Safwat15-Feb-16 7:19
Sandy Safwat15-Feb-16 7:19 
AnswerRe: single submit button with multiple tabs Pin
Richard Deeming15-Feb-16 8:09
mveRichard Deeming15-Feb-16 8:09 
GeneralRe: single submit button with multiple tabs Pin
Sandy Safwat15-Feb-16 9:19
Sandy Safwat15-Feb-16 9:19 
GeneralRe: single submit button with multiple tabs Pin
Richard Deeming15-Feb-16 9:32
mveRichard Deeming15-Feb-16 9:32 
GeneralRe: single submit button with multiple tabs Pin
Sandy Safwat15-Feb-16 10:27
Sandy Safwat15-Feb-16 10:27 
GeneralRe: single submit button with multiple tabs Pin
Richard Deeming15-Feb-16 10:48
mveRichard Deeming15-Feb-16 10:48 
GeneralRe: single submit button with multiple tabs Pin
Mycroft Holmes15-Feb-16 13:39
professionalMycroft Holmes15-Feb-16 13:39 
GeneralRe: single submit button with multiple tabs Pin
Sandy Safwat15-Feb-16 18:38
Sandy Safwat15-Feb-16 18:38 
QuestionGet the name of the machine I'm remoted from... Pin
dandy7215-Feb-16 5:40
dandy7215-Feb-16 5:40 
AnswerRe: Get the name of the machine I'm remoted from... Pin
Gerry Schmitz15-Feb-16 6:28
mveGerry Schmitz15-Feb-16 6:28 
AnswerRe: Get the name of the machine I'm remoted from... Pin
Eddy Vluggen16-Feb-16 11:08
professionalEddy Vluggen16-Feb-16 11: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.