K
Ken Allen
I am developing a small utility program that must perform a considerable
amount of 'background' or 'research' work before it can display any user
interface. In general it can take 3-15 seconds to perform all of the
work requured before we display any user interface. So we have
determined that the utility should have a splash screen to assure the
user that the program is executing and will provide results shortly.
I should also note that we are now using Visual Studio 2005 and the
utility is written in C#.
Obviously we do not want the splash screen displayed in the same thread
as the work that is being performed, since that leads to the standard
problems of the contents not being fully populated and not being
repainted if the window is obscured and uncovered once more.
So we are left with two basic approaches:
1. Display the splash screen in a second thread and perform the
initialization work in the main thread.
2. Display the splash screen in the main thread and launch the
initialization work in another thread.
The former requires a loop that makes calls to DoEvents() so that the
screen is refreshed in a timely manner. Since the main thread is in
control, it is much easier to collect the information from the
initialization thread and to control the splash screen thread.
The latter is a bit more awkward to envision, as the initialization
thread may be controlled from either the main thread itself or from
inside the splash screen form class (more obscure, but...). This
approach has the downside of making it a bit more difficult to retrieve
information from the initialization thread (but not too difficult) and
to determine when the initialization thread is complete.
Is there a best practice or standard model for this activity in managed
..Net utilities?
-ken
amount of 'background' or 'research' work before it can display any user
interface. In general it can take 3-15 seconds to perform all of the
work requured before we display any user interface. So we have
determined that the utility should have a splash screen to assure the
user that the program is executing and will provide results shortly.
I should also note that we are now using Visual Studio 2005 and the
utility is written in C#.
Obviously we do not want the splash screen displayed in the same thread
as the work that is being performed, since that leads to the standard
problems of the contents not being fully populated and not being
repainted if the window is obscured and uncovered once more.
So we are left with two basic approaches:
1. Display the splash screen in a second thread and perform the
initialization work in the main thread.
2. Display the splash screen in the main thread and launch the
initialization work in another thread.
The former requires a loop that makes calls to DoEvents() so that the
screen is refreshed in a timely manner. Since the main thread is in
control, it is much easier to collect the information from the
initialization thread and to control the splash screen thread.
The latter is a bit more awkward to envision, as the initialization
thread may be controlled from either the main thread itself or from
inside the splash screen form class (more obscure, but...). This
approach has the downside of making it a bit more difficult to retrieve
information from the initialization thread (but not too difficult) and
to determine when the initialization thread is complete.
Is there a best practice or standard model for this activity in managed
..Net utilities?
-ken