Jonathan Beerhalter
Jonathan Beerhalter

Reputation: 7407

Is it possible to measure how long it takes a Winforms form to appear?

I have a winforms app, and pops up some windows from time to time depending on what the user clicks on. Lately, users have been complaining that the pop ups take too long to appear. If I profile the code, or put in a Stopwatch, I see that my C# code finishes process the Show() method in about 50ms, but the window itself won't appear for almost a second.

Is there any way to measure that amount time until the window actually appears?

Upvotes: 2

Views: 802

Answers (2)

mservidio
mservidio

Reputation: 13057

I think the Shown event fires after the drawing is completed.

See Form.Shown Event and Order of Events in Windows Forms

Upvotes: 3

Anders Abel
Anders Abel

Reputation: 69260

Measuring the time until the first OnPaint call could be a way. It is called as a response to the WM_PAINT message, which is sent by Windows to a Window when it should be redrawn. If you take a measurement both before and after the base.OnPaint() call you can also see how long the actual drawing code takes to complete.

Upvotes: 2

Related Questions