Link to home
Start Free TrialLog in
Avatar of Evan Cutler
Evan CutlerFlag for United States of America

asked on

Progress bar on Form / Progress in Class Function

Greetings.
I have a progress bar on Form1.cs

A button on Form1.cs calls the "click" event, which creates an object

DAT2XLS  document = DAT2XLS(sourcefile, schemafile);

Then it executes the function:

DAT2XLS.doyourwork();

I am attempting to do this in the background.

I need to have doyourwork() report progress.
Since it is in a different class, I don't know how to tell the progressbar what the progress is.

I appreciate any wisdom on this.

Thank you.
Avatar of Vel Eous
Vel Eous

You could create a custom event handler in your class doing the work, then your form can reference it and become aware when the event is triggered.

http://www.switchonthecode.com/tutorials/csharp-snippet-tutorial-custom-event-handlers
Avatar of Evan Cutler

ASKER

ok.
I read the article, but a bit confused.
Here's my form code:

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            DAT2XLS D2X = new DAT2XLS(TXTBinFile.Text, TXTXMLSchemaFile.Text);
            D2X.ETLRUN();
        }


       private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
       {
           PBXFR.Value = e.ProgressPercentage;
       }

Open in new window



and Here's my class (some of it):

    public class DAT2XLS
    {
        String DatFile;
        String SchemaFile;

        public DAT2XLS(String Dat, String Schema)
        {
            DatFile = Dat;
            SchemaFile = Schema;
        }

        public void ETLRUN()
        {
                //sudocode here
                open file;
                totallines;  //gives the "100%"
                start file back at top;
                linecount = 0;
                do while (!end of file)
                         read line, do something //gives current line
                percent = linecount / totallines;
                SEND PERCENT VALUE BACK TO PROGRESSCHANGED
        }

Open in new window


ok...how do I tell ETLRUN() to throw the percentage back to ProgressChanged in the form class?  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America 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
Thanks for all of your help...
I'm having issues still

D2X_Progress is not sending the value to ProgressChanged (I think)...
or ProgressChanged is not accepting something.

The PBXFR.Value is not updating.

Thank you so much for walking me through this.
Never mind, it was my calculations that didn't push the value.
THANK YOU SO MUCH!!!!

This worked perfectly.
This is an invaluable tool.