Link to home
Start Free TrialLog in
Avatar of JunkMan
JunkManFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Backgroundworker with inner backgroundworker!!

Hi,

I don't know if the title is appropriate but by reading u might understand a little bit more, at least i hope so...

Basically i have a webservice setup, i need to on entering the form, a background worker to be initialized to iterate an array that contains ids of a user, that will call another background worker, that will load the user details from the webservice, when this concludes it will create a form and store it in an hash table, when all the forms have been created i want the first background worker to conclude and open all of the forms. The form that is doing this has a progress bar, that is updated via a timer, thats why i need the "TOP" background worker. I hope it makes sence...

I've tried several things, like: (only the essencials)

int[] ids = new int[3]{1,2,3};
int currentIdIndex = 0;
hashtable frms = new hashtable();
bgw1 doWork{
    bgw2.runassync(currentIdIndex);
}
bgw1 onComplete{
    foreach(Form f in frms)
      f.Show();
}
bgw2 doWork{
    e.result = webservice.getDetails(ids[(int)e.argument]);
}
bgw2 onComplete{
   if(e.result !=null){
       frmDetails frm = new frmDetails();
       frm.myDS = e.result as dataset;
       if(currentIdIndex < ids.length){
          currentIdIndex++;
          bgw2.runassync(currentIdIndex);
       }

    }
}

The problem is that the bgw1 concludes straight after the bgw2 1st iteration has concluded...

BTW, this is just a example is not actual working code!! i just wrote it from the top of my head, so don't bother about typos, but u get the idea!!! at least i hope so...

Thanks for your help...

Regards,
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JunkMan

ASKER

Hi gregory,

I've realized that later on, it was a very long day, and for the matter, the first time i've actually developed windows forms and using threads, i was just confused!!

Anyway just to make things fair... post an example code, so that anyone can view it if they need, and i'll accept you question..

Thanks..
Avatar of JunkMan

ASKER

TheLearnedOne: I've asked gregoryyoung to provide an example, since he knows the solution, to be fair with any other person that needs the same solution and also to prove himself worth of the 400 points. He didn't comply with this therefore i haven't assigned him the points..
"If you want to put up more complete code I might be able to help walk you through it."

I am not going to try to scrap together an environment to make your pseudocode work.
Avatar of JunkMan

ASKER

And i'm not asking you to do so, just a simple algorithym or even the same way i provided my example, alternatively i could give you the points but i'll certainly wont give A for it...

Regards,