• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

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,
0
JunkMan
Asked:
JunkMan
  • 3
  • 2
1 Solution
 
gregoryyoungCommented:
I don't see any reason why you need two background workers ?

The 1st background worker should be able to do both jobs without any issue (or real performance hit)

If you want to put up more complete code I might be able to help walk you through it.

Cheers,

Greg
0
 
JunkManAuthor Commented:
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..
0
 
JunkManAuthor Commented:
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..
0
 
gregoryyoungCommented:
"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.
0
 
JunkManAuthor Commented:
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,
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now