0

My question might seem silly to you, but I realized that moving my applications form makes the code inside it run slower. E.g. when I load a bitmap image and apply some image editing algorithms on it, it takes about 22 secs for the whole process to finish. But if I move the form during execution, it adds some 3-4 extra seconds to the elapsed time. I was able to spot the delay using a Stopwatch. So how can I get around this behaviour, if possible at all?

1 Answer 1

0

This is just an hypothesis that requires your investigation, as you didn't post any code and thus it is impossible to really know what is going on.


Most probably you move the boundaries of the image outside the screen. When you move in again, the windowing engine will do some draw calls on those rectangles to be redrawn. The same happens on resize when you enlarge but not when you shrink the window.

If this is the case, then you will not experience any extra draw calls as long as you don't cover/uncover areas of the image.

So this is not an answer but in your place I would override the Paint() method and log how many excess calls are made. Based on this, I'd search for a solution, such as suppress those calls like this:

public override void Paint()
{
    if (algorithmRunning)
    {
        return; // suppress any further computations
    }

    base.Paint(); // do actual redraws
}

This code is just an example, you'll have to fix it according to the MSDN documentation.

What you should NOT do is just hook into the OnPaint() event, because then you'll still have the actual Paint() method called.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.