J
John Davison
Given a piece of code that may take some time to complete, I want to
display an animation in a popup window. The popup window contains a
button allowing the user to cancel the operation. When the code starts,
the popup window shows, and when either the code is finished or the user
hits cancel, the window is closed.
The issue is threading. ShowDialog() won't work because you have to
execute the rest of the code. So we have to use Show(). However, the
control stops painting itself because the execution is doing something else.
The obvious solution is to create the window on another thread and let
it run over there. Then you get into all the issues of threading,
(BeginInvoke, Invoke, etc...) For example, one of the properties of the
window is Text, which changes the Text property of a Label. You can't
do that until the window is actually loaded. So my solution for that
would either be a) wait in the code for the form to be loaded, or b)
queue up changes to the Text property internally in the popup window
until the form is loaded.
It seems clunky to me to have to write another function just to load the
popup window (for the ThreadStart delegate.)
It always seems like I'm coming up with workarounds and hacks to do
stuff like this. Does anyone have any good techniques they would care
to share?
John Davison
display an animation in a popup window. The popup window contains a
button allowing the user to cancel the operation. When the code starts,
the popup window shows, and when either the code is finished or the user
hits cancel, the window is closed.
The issue is threading. ShowDialog() won't work because you have to
execute the rest of the code. So we have to use Show(). However, the
control stops painting itself because the execution is doing something else.
The obvious solution is to create the window on another thread and let
it run over there. Then you get into all the issues of threading,
(BeginInvoke, Invoke, etc...) For example, one of the properties of the
window is Text, which changes the Text property of a Label. You can't
do that until the window is actually loaded. So my solution for that
would either be a) wait in the code for the form to be loaded, or b)
queue up changes to the Text property internally in the popup window
until the form is loaded.
It seems clunky to me to have to write another function just to load the
popup window (for the ThreadStart delegate.)
It always seems like I'm coming up with workarounds and hacks to do
stuff like this. Does anyone have any good techniques they would care
to share?
John Davison