Wrong e.Percentage shown by "Work" status handler

Hi,
I hooked Work's Status (the event handler) to a debug procedure that prints the percentage and a status message

work.Status = new StatusEventHandler(DBSyncManager_OnProgress);

After I call work.BuildDifferences ,using the following
work.BuildFromDifferences(differences, Options.Default, true);

I am getting 5 digits percentages displayed in my log :
Calculating work to do : 0
100
200
...

33800

Is it a bug ? If not how can I get Work's percentage calculated in regular 100% format?

Thanks :)

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hello Vladimir,

    Yes, I see what you're talking about from when I run the SQL Compare code snippets. When I compare a larger database (not the example widget databases), I do seem to get a much lower percentage, it only goes up to 275%. I think that the issue is that on smaller databases, the estimation of the work that needs to be done gets way off, because the first time the StatusEventHandler gets called, the e.Percentage is already 100%!

    I'll see if I can contact David Connell about this, as he's got a better understanding about the StatusEventHandler delegates in SQL Toolkit.
  • fordc03fordc03 Posts: 49 Bronze 2
    Hey guys, when you use the StatusEventHandler on the work object...for each work item it does is 1 percentage point to the StatusEventHandler...which means that if you got 1,000 work items, your progress percentage will go to 1,000%

    You need a seperate delegate for the work if you're going to calculate percentage and set your progress bar to the max of the number of work items or do some fancy divide by some number to equal 100 so that you don't blow out your progress bar.

    I broke that in so many ways when playing around with this... :)

    Anyway, best way is to do something like this...

    //Here is the callback for your status
            private void StatusCallback(object sender, StatusEventArgs e)
            {
                    if (e.Message != null)
                    {
                        lblProgress.Text = string.Format("{0}", e.Message);
                    }
    
                    if (e.Percentage != -1)
                    {
                        pbCompare.Value = e.Percentage;
                        lblPercent.Text = string.Format("{0}", pbCompare.Value);
                    }
            }
    

    Then here is the one for your ProgressBar:
                        //create a counter
                        int diffCounter = 0;
                        if (differences != null)
                            foreach (Difference difference in differences)
                            {
                                //make sure the difference is selected so it is included in the synchronization     
                                if (difference.Type.ToString() != "Equal")
                                {
                                    difference.Selected = true;
                                    diffCounter++;
                                }
                            }
                        pbCompare.Value = 0;
                        pbCompare.Maximum = diffCounter;
    

    I guess it's 1 point for each difference...I think...Test this and see if it works for you :)

    Actually, I guess this wouldn't work, you'd have to re-calculate the percentage everytime you entered the delegate...that's not a good thing.

    Guess it's a bug!! :)
Sign In or Register to comment.