Backgroundworker with inner backgroundworker!!

Posted on 2006-05-05
Last Modified: 2012-05-05

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{
bgw1 onComplete{
    foreach(Form f in frms)
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){


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...

Question by:JunkMan
    LVL 37

    Accepted Solution

    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.


    LVL 3

    Author Comment

    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..

    LVL 3

    Author Comment

    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..
    LVL 37

    Expert Comment

    "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.
    LVL 3

    Author Comment

    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...


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now