c# - compact framework: Update of label in thread not working -


in program mobile device (windows mobile), use compact framework 3.5, download file , want monitor progress, showing in windows.forms.label.

here code:

start of thread (in button-click-event)

threadstart ts = new threadstart(() => downloadfile(servername, downloadedfilename, this.lbldownloadpercentage)); thread t = new thread(ts); t.name = "download"; t.start(); t.join(); 

my thread-method

static void downloadfile(string servername, string downloadedfilename, label statuslabel) {       httpwebrequest httprequest = (httpwebrequest)webrequest.create(servername);             {             //download , save file ...             setpercentage(statuslabel, currentprogress);       } while(...)  } 

the method update label-text

 private static void setpercentage(label targetlabel, string value)  {       if (targetlabel.invokerequired)       {            targetlabel.invoke((methodinvoker)delegate            {                 targetlabel.text = value;            });       }       else       {            targetlabel.text = value;       }  } 

the download , saving part works fine, when comes targetlabel.invoke-part (3rd code-snippet) program stops doing anything. no crash, no error message, no exception. stops.

what going wrong here?

btw, if leave t.join() away, thread doesn't start @ all... (why that?)

am sure deadlock here.

main thread waiting in t.join(); when worker thread calls targetlabel.invoke main thread can't invoke since waiting in join never going happen. situation called deadlock in computer science.

remove join() , should work.

btw, if leave t.join() away, thread doesn't start @ all... (why that?)

not sure that, not how supposed be, try debug application , figure out. if not found provide more info help.

hope helps


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -