c# - Parallel calls of two methods using threads - One executing before one finished -


i using multi threading in c# application upload images.

the flow is, first resizing images. second uploading them.

code :

upload button click

private void button_click_1(object sender, routedeventargs e) {             resizeimagesatlocal();             uploadimagetocloud(); }                  private void resizeimagesatlocal() {             var worker = new backgroundworker                 {                     workerreportsprogress = true                 };              worker.dowork += worker_resizeimages;             worker.progresschanged += worker_resizeprogresschanged;              worker.runworkerasync(); }  private void worker_resizeprogresschanged(object sender, progresschangedeventargs e) {    resizeprogress.value = e.progresspercentage; }  private void worker_resizeimages(object sender, doworkeventargs e) {     ... }   private void uploadimagetocloud() {             var worker = new backgroundworker();             worker.workerreportsprogress = true;             worker.dowork += worker_uploadimages;             worker.progresschanged += worker_uploadprogresschanged;              worker.runworkerasync(); }  void worker_uploadprogresschanged(object sender, progresschangedeventargs e) {     uploadprogress.value = e.progresspercentage; }  void worker_uploadimages(object sender, doworkeventargs e) {   ... } 

the problem is, resizeimagesatlocal not yet finished, , upload image started executing, causing issue..

is there way make sure.. resizeimagesatlocal job done, , can call upload method.

you can use task present 4.0 version.

you can (pseudocode):

task.factory.startnew(()=> { }). continuewwith(...); 

continuewith called after startnew task finished


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -