I'm looking to implement a quick and dirty way of measuring the UI performance of a set of winforms. My idea is to put in System.Diagnostic timing calls into the code base and detect when the time from when the page is requested to when it is completely drawn and available to the user. Is this even possible? Is there an initial event I can hook into and an event I can hook into when the form has completely? painted. I know there is a Paint event but this is when the form starts to draw but this isn't going to help me.
I'm a web developer dealing with some windows forms hence the obvious question.
You can start the
Stopwatchexactly before executing the constructor of yourFormor in the first line of your constructor.It is a good idea to start the
Stopwatchbefore the constructor, because when you start it inside the constructor, already base class constructor will have finished running, so you'll be excluding those timings if you decide to start it in the first line of the constructor.Then stop the
StopwatchinForm.Shownevent. It will be raised when the form is fully shown to the user.Then use
Stopwatch.Elapsedto read the time taken for the form to load.As @HansPassant noted in comments, you may need to add
this.Update();in theShownevent handler so that we can make sure all children are painted fully.