.net - Will calling a progress report method slow down a C# file download on Windows Phone 7 significantly? -


i have windows phone 7 (7.1) method in c# given url in string form downloads contents of url file (see code below). can see code, assign downloadprogresschanged() event handler. in handler, if caller provided iprogress object, call report() method on object. given potential user having slow web connection, want make sure download go fast possible. calling iprogress.report() method in webclient's downloadprogresschanged() callback slow down download considerably?

i'm not familiar enough iprogress.report() know if executes on current thread or calling thread. execute on calling thread? concern repetitive thread switch bog things down. i'll wrap call method in task.run() call keep ui thread happy. in case, i'll ask if there potential problems code far bogging down ui thread concerned?

any other comments on code pertaining structure or performance appreciated. note, i'm using microsoft.bcl.async package in app.

update (added later): in regards thread switching, apparently downloadprogresschanged() event raised on ui thread, not download thread, there no need fancy dispatcher or ui updates in scenario. @ least according code project article:

progress reporting in c# 5 async

    public static void urltofile(string strurl, string strdestfilename, iprogress<int> progress, int inumsecondstowait = 30)     {         strurl = strurl.trim();          if (string.isnullorwhitespace(strurl))             throw new argumentexception("(misc::urltofile) url empty.");          strdestfilename = strdestfilename.trim();          if (string.isnullorwhitespace(strdestfilename))             throw new argumentexception("(misc::urltofile) destination file name empty.");          if (inumsecondstowait < 1)             throw new argumentexception("(misc::urltofile) number of seconds wait less 1.");          // create isolated storage file.         streamwriter sw = openisostorfileasstreamwriter(strdestfilename);          // if stream writer null, file not created.         if (sw == null)             throw new system.io.ioexception("(misc::urltofile) error creating or writing file named: " + strdestfilename);          // asynchronous download.  note, silverlight version of webclient *not* implement          //  idisposable.         webclient wc = new webclient();          try         {             // create download progress changed handler can pass on progress             //  reports caller if provided progress report object.             wc.downloadprogresschanged += (s, e) =>             {                 // have progress report handler?                 if (progress != null)                     // yes, call it.                     progress.report(e.progresspercentage);             };              // use lambda expression "completed" handler             //  writes contents file.             wc.openreadcompleted += (s, e) =>                 e.result.copyto(sw.basestream);              // make call download file.             wc.downloadstringasync(new uri(strurl));         }                 {             // make sure stream cleaned up.             sw.flush();             sw.close();              // make sure streamwriter diposed of.             sw.dispose();         } // try/finally          // cancellationtokensource srccanceltoken = new cancellationtokensource();         // srccanceltoken.cancelafter(timespan.fromseconds(inumsecondstowait));     } // public static void urltofile() 

no, download progress check not affect download speed. because items checked not downloaded per-se. when initiate download, size declaration (content length) - used reference complete file. then, size of local (downloaded) byte content checked , ratio can built 2 values.

note: not apply streaming, obvious reasons, since there no final size estimate.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -