Click here to Skip to main content
15,896,154 members
Home / Discussions / C#
   

C#

 
QuestionTrying to show progress using DownloadDataAsync Pin
steve_rm1-Aug-09 4:23
steve_rm1-Aug-09 4:23 
AnswerRe: Trying to show progress using DownloadDataAsync Pin
Abhijit Jana1-Aug-09 6:18
professionalAbhijit Jana1-Aug-09 6:18 
QuestionRe: Trying to show progress using DownloadDataAsync Pin
Steve1_rm1-Aug-09 6:44
Steve1_rm1-Aug-09 6:44 
AnswerRe: Trying to show progress using DownloadDataAsync Pin
Eddy Vluggen1-Aug-09 7:00
professionalEddy Vluggen1-Aug-09 7:00 
GeneralRe: Trying to show progress using DownloadDataAsync Pin
Steve1_rm1-Aug-09 7:33
Steve1_rm1-Aug-09 7:33 
GeneralRe: Trying to show progress using DownloadDataAsync Pin
Eddy Vluggen1-Aug-09 8:39
professionalEddy Vluggen1-Aug-09 8:39 
AnswerRe: Trying to show progress using DownloadDataAsync Pin
Luc Pattyn1-Aug-09 8:43
sitebuilderLuc Pattyn1-Aug-09 8:43 
AnswerRe: Trying to show progress using DownloadDataAsync Pin
Alan N1-Aug-09 13:57
Alan N1-Aug-09 13:57 
Hi,
I've got a few comments on the code although it does look essentially correct and I can't see anything that is obviously broken.

1) In the completion handler there is no check for success and without that it is not possible to draw any conclusions about other parts of the operation.
2) In the example given the results string is very short, only 6 characters, and so it is quite possible that the first progress notification is 100%. Log the e.BytesReceived and e.TotalBytesToReceive values to get a bit more info here.
3) Bear in mind that UpdateAvailable will return before the download is complete as DownloadDataAsync is non blocking. This leaves the WebClient object eligible for garbage collection and that could cause problems.

Example code for checking successful completion:
private void DownloadDataCallback (Object sender, DownloadDataCompletedEventArgs e)
{
   // If the request was not canceled and did not throw
   // an exception, get the result.
   if (e.Error == null && !e.Cancelled)
   {
     byte[] data = e.Result;
   } 
   else
   {
     //error or cancelled
   }
}

I've read the other responses and it has been suggested that you should not update the progress bar directly due to cross thread issues. I disagree as WebClient operates in the same way as BackgroundWorker with event notifications marshaled to the UI thread. This means your code is safe without using Invoke on the controls.

Alan.
QuestionConnecting C# application to online MS Access database Pin
Alexander Szmidt1-Aug-09 3:43
Alexander Szmidt1-Aug-09 3:43 
AnswerRe: Connecting C# application to online MS Access database Pin
Dave Kreskowiak1-Aug-09 5:10
mveDave Kreskowiak1-Aug-09 5:10 
AnswerRe: Connecting C# application to online MS Access database Pin
nelsonpaixao1-Aug-09 5:12
nelsonpaixao1-Aug-09 5:12 
AnswerRe: Connecting C# application to online MS Access database Pin
Eddy Vluggen1-Aug-09 7:06
professionalEddy Vluggen1-Aug-09 7:06 
QuestionCan I write programs in C # to Micro Controllers Pin
Nasir131-Aug-09 2:33
Nasir131-Aug-09 2:33 
AnswerRe: Can I write programs in C # to Micro Controllers Pin
DaveyM691-Aug-09 2:47
professionalDaveyM691-Aug-09 2:47 
RantRe: Can I write programs in C # to Micro Controllers Pin
Nasir131-Aug-09 3:58
Nasir131-Aug-09 3:58 
GeneralRe: Can I write programs in C # to Micro Controllers Pin
Dave Kreskowiak1-Aug-09 5:07
mveDave Kreskowiak1-Aug-09 5:07 
GeneralRe: Can I write programs in C # to Micro Controllers Pin
DaveyM691-Aug-09 7:03
professionalDaveyM691-Aug-09 7:03 
AnswerRe: Can I write programs in C # to Micro Controllers Pin
HimanshuJoshi1-Aug-09 3:54
HimanshuJoshi1-Aug-09 3:54 
GeneralRe: Can I write programs in C # to Micro Controllers Pin
Nasir131-Aug-09 4:34
Nasir131-Aug-09 4:34 
RantRe: Can I write programs in C # to Micro Controllers Pin
Nasir131-Aug-09 4:39
Nasir131-Aug-09 4:39 
GeneralRe: Can I write programs in C # to Micro Controllers Pin
OriginalGriff1-Aug-09 4:58
mveOriginalGriff1-Aug-09 4:58 
AnswerRe: Can I write programs in C # to Micro Controllers [modified] Pin
mustang861-Aug-09 16:32
mustang861-Aug-09 16:32 
GeneralRe: Can I write programs in C # to Micro Controllers Pin
OriginalGriff2-Aug-09 0:45
mveOriginalGriff2-Aug-09 0:45 
QuestionCreate DAL/ BLL Pin
Chazzysb1-Aug-09 1:23
Chazzysb1-Aug-09 1:23 
AnswerRe: Create DAL/ BLL Pin
Eddy Vluggen1-Aug-09 7:13
professionalEddy Vluggen1-Aug-09 7:13 

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.