Click here to Skip to main content
15,896,726 members
Home / Discussions / C#
   

C#

 
Questionprogramming ideas Pin
MegaBaitas28-Mar-13 3:45
MegaBaitas28-Mar-13 3:45 
AnswerRe: programming ideas Pin
Richard MacCutchan28-Mar-13 3:58
mveRichard MacCutchan28-Mar-13 3:58 
AnswerRe: programming ideas Pin
PIEBALDconsult28-Mar-13 4:01
mvePIEBALDconsult28-Mar-13 4:01 
Generalprogramming ideas Pin
MegaBaitas28-Mar-13 5:11
MegaBaitas28-Mar-13 5:11 
GeneralRe: programming ideas Pin
PIEBALDconsult28-Mar-13 10:14
mvePIEBALDconsult28-Mar-13 10:14 
AnswerRe: programming ideas Pin
Alan Balkany1-Apr-13 5:08
Alan Balkany1-Apr-13 5:08 
QuestionBoost parralel messaging performance (TPL / Async) Pin
KillerX12328-Mar-13 2:29
KillerX12328-Mar-13 2:29 
QuestionMy issue is regarding handling multiple backgroud worker and multiple progressbar Pin
Tridip Bhattacharjee28-Mar-13 0:31
professionalTridip Bhattacharjee28-Mar-13 0:31 
my main problem is when i add dynamically a progressbar on flowLayoutPanel1 for each request then how can i increase right progressbar value frombackgroundWorker1_ProgressChanged event

when user click on start button then i will call RunWorkerAsync function of background worker....it is fine. here i am writing a sample code and try to show my problem.

my form has one textbox, one button and one flowLayoutPanel1 with FlowDirection topdown.

when user enter any url in textbox and click on start button then i will start file download with BackGroundWorker and add one progress bar dynamically on flowLayoutPanel1. 10 file can be downloaded at a time. so when user enter ten url one after after one and click on submit button then ten file will be downloading in background.

my problem is how to increment 10 progress bar progress properly from backgroundWorker1_ProgressChanged event another issue is when any file download will complete then the progress bar for which it has been created will be removed from panel

here is my full code. please have a look and tell me what i need to do to achieve my task. if anyone see there is problem in my code for which a dead lock may appear then also please guide me how to avoid dead lock. here is my code

C#
public partial class Form1 : Form
    {
        static int pbCounter = 1;

        public Form1()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            ProgressBar pb = new ProgressBar();
            if (pbCounter <= 10)
            {
                pb.Width = txtUrl.Width;
                flowLayoutPanel1.Controls.Add(pb);
                pbCounter++;

                System.ComponentModel.BackgroundWorker backgroundWorker1 = new System.ComponentModel.BackgroundWorker();

                backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
                backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
                backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);

                backgroundWorker1.RunWorkerAsync();
            }
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            // Get the BackgroundWorker that raised this event.
            System.ComponentModel.BackgroundWorker worker = sender as System.ComponentModel.BackgroundWorker;

            // Assign the result of the computation
            // to the Result property of the DoWorkEventArgs
            // object. This is will be available to the  
            // RunWorkerCompleted eventhandler.
            //#e.Result = ComputeFibonacci((int)e.Argument, worker, e);
        }

        // This event handler deals with the results of the
        // background operation.
        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // First, handle the case where an exception was thrown.
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message);
            }
            else if (e.Cancelled)
            {
                //# "Canceled";
            }
            else
            {
                pbCounter--;
                // Finally, handle the case where the operation  
                // succeeded.
                //#resultLabel.Text = e.Result.ToString();
            }
        }

        // This event handler updates the progress bar.
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.progressBar1.Value = e.ProgressPercentage;
        }

    }

tbhattacharjee

AnswerRe: My issue is regarding handling multiple backgroud worker and multiple progressbar Pin
Thomas Duwe28-Mar-13 5:26
Thomas Duwe28-Mar-13 5:26 
GeneralRe: My issue is regarding handling multiple backgroud worker and multiple progressbar Pin
Tridip Bhattacharjee30-Mar-13 5:35
professionalTridip Bhattacharjee30-Mar-13 5:35 
GeneralRe: My issue is regarding handling multiple backgroud worker and multiple progressbar Pin
Thomas Duwe1-Apr-13 5:37
Thomas Duwe1-Apr-13 5:37 
QuestionHttpWebRequest and strange networking errors Pin
cjb11028-Mar-13 0:10
cjb11028-Mar-13 0:10 
QuestionHow to enlarge the recording voice Pin
Star.jon27-Mar-13 22:46
Star.jon27-Mar-13 22:46 
AnswerRe: How to enlarge the recording voice Pin
Bernhard Hiller27-Mar-13 23:01
Bernhard Hiller27-Mar-13 23:01 
GeneralRe: How to enlarge the recording voice Pin
Star.jon27-Mar-13 23:05
Star.jon27-Mar-13 23:05 
GeneralRe: How to enlarge the recording voice Pin
Dave Kreskowiak28-Mar-13 2:00
mveDave Kreskowiak28-Mar-13 2:00 
Questionerror in crystal reports Pin
User349027-Mar-13 13:36
User349027-Mar-13 13:36 
AnswerRe: error in crystal reports Pin
Abhinav S27-Mar-13 17:58
Abhinav S27-Mar-13 17:58 
AnswerRe: error in crystal reports Pin
V.27-Mar-13 22:21
professionalV.27-Mar-13 22:21 
GeneralRe: error in crystal reports Pin
User349028-Mar-13 7:49
User349028-Mar-13 7:49 
GeneralRe: error in crystal reports Pin
V.28-Mar-13 8:19
professionalV.28-Mar-13 8:19 
QuestionHow to Async download multiple files using webclient simultaneously? Pin
Tridip Bhattacharjee27-Mar-13 8:01
professionalTridip Bhattacharjee27-Mar-13 8:01 
QuestionScreenshots -> Video file Pin
ADASD33333227-Mar-13 4:06
ADASD33333227-Mar-13 4:06 
AnswerRe: Screenshots -> Video file Pin
Abhinav S29-Mar-13 4:00
Abhinav S29-Mar-13 4:00 
QuestionSaving Screensaver in C# Pin
greylakota27-Mar-13 3:34
greylakota27-Mar-13 3:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.