By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.

Unresponsive UI during lengthy operation ?

P: n/a
Hi all,

I'm making a Windows application that does some lengthy retrieval operations
from a database and possibly from a internet resource.

I want to show that the operation is going on, by using an Animated .gif in
a picture box. Also note that this PictureBox also acts as the button to
invoke this lengthy operation. In other words, the user will click the
PicBox to start the operation. When clicked, I update the Image property of
the PicBox to the Animated .gif, and then call the lengthy method. I also
change the Tooltip of the PicBox to something like "Retrieving... please
wait...". At the end of the operation, I want to reset the Image property of
the PicBox.

The problem is that the PicBox image just freezes until the operation is
complete, by then it is already time to reset the Image. How do I show the
progress in this case ? The tooltip however, gets changed, which means that
the problem is mainly with updating the image. I have also noticed that the
form will not repaint, if I bring another application over it, and restore
it.

I have tried to call Application.DoEvents() at the start of my lengthy
method, but it never seems to have any effect whatsoever.

My concepts are a bit shaky as far as Asynchronous calls are concerned, so I
was wondering if there is any other way to prevent the UI from freezing up.

Any help is appreciated.

Regards,

Cerebrus.
Feb 15 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Just to add a question...

Is Multi-threading the only answer

Regards,

Cerebrus.

Feb 15 '06 #2

P: n/a

well there are two ways i would recomend
1. use multithreading ( start a seperate thread ,,,, Background worker
would be suitable for this )
2. start the operation asynchronous if it supports this feature (
webservices and database objects often provide a begin and end invoke )

maybe someone else has other options

regards

Michel Posseth [MCP]

"Cerebrus99" <zo*****@sify.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
Hi all,

I'm making a Windows application that does some lengthy retrieval
operations
from a database and possibly from a internet resource.

I want to show that the operation is going on, by using an Animated .gif
in
a picture box. Also note that this PictureBox also acts as the button to
invoke this lengthy operation. In other words, the user will click the
PicBox to start the operation. When clicked, I update the Image property
of
the PicBox to the Animated .gif, and then call the lengthy method. I also
change the Tooltip of the PicBox to something like "Retrieving... please
wait...". At the end of the operation, I want to reset the Image property
of
the PicBox.

The problem is that the PicBox image just freezes until the operation is
complete, by then it is already time to reset the Image. How do I show the
progress in this case ? The tooltip however, gets changed, which means
that
the problem is mainly with updating the image. I have also noticed that
the
form will not repaint, if I bring another application over it, and restore
it.

I have tried to call Application.DoEvents() at the start of my lengthy
method, but it never seems to have any effect whatsoever.

My concepts are a bit shaky as far as Asynchronous calls are concerned, so
I
was wondering if there is any other way to prevent the UI from freezing
up.

Any help is appreciated.

Regards,

Cerebrus.

Feb 15 '06 #3

P: n/a
See:

Resources about asynchronous operations
http://www.mztools.com/resources_net...nousOperations

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
"Cerebrus99" <zo*****@sify.com> escribió en el mensaje
news:ut**************@TK2MSFTNGP09.phx.gbl...
Hi all,

I'm making a Windows application that does some lengthy retrieval
operations
from a database and possibly from a internet resource.

I want to show that the operation is going on, by using an Animated .gif
in
a picture box. Also note that this PictureBox also acts as the button to
invoke this lengthy operation. In other words, the user will click the
PicBox to start the operation. When clicked, I update the Image property
of
the PicBox to the Animated .gif, and then call the lengthy method. I also
change the Tooltip of the PicBox to something like "Retrieving... please
wait...". At the end of the operation, I want to reset the Image property
of
the PicBox.

The problem is that the PicBox image just freezes until the operation is
complete, by then it is already time to reset the Image. How do I show the
progress in this case ? The tooltip however, gets changed, which means
that
the problem is mainly with updating the image. I have also noticed that
the
form will not repaint, if I bring another application over it, and restore
it.

I have tried to call Application.DoEvents() at the start of my lengthy
method, but it never seems to have any effect whatsoever.

My concepts are a bit shaky as far as Asynchronous calls are concerned, so
I
was wondering if there is any other way to prevent the UI from freezing
up.

Any help is appreciated.

Regards,

Cerebrus.

Feb 15 '06 #4

P: n/a
> Is Multi-threading the only answer

Yes, in my opinion. Run the lengthy operation on a new thread. Devise a
mechanism for communication between the new thread and the ui thread. There
are two easy choices.

1. Worker thread updates properties in a class or module with synclock, ui
thread has a timer and samples them regularly also using synclock.

2. Worker thread posts info to ui thread directly via invoke or
begininvoke/endinvoke.

Probably #2 is most commonly used, I prefer #1.
Feb 15 '06 #5

P: n/a
"Cerebrus99" <zo*****@sify.com> schrieb:
My concepts are a bit shaky as far as Asynchronous calls are concerned, so
I
was wondering if there is any other way to prevent the UI from freezing
up.


Multithreading in Windows Forms applications
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 15 '06 #6

P: n/a
Thank you very much everyone for all that information !

I have now realized that knowledge of Multithreading and Asynchronous
operations were one area that I cannot do without. So, I have read up
on some of those useful links (Thanks for Carlos and Herfried).

I have now been able to implement the following in my application :

1. The Click of the PicBox now starts an asynchronous process to
retrieve all the data.
2. During this operation, the UI remains responsive and the PicBox
shows an Animating .gif.
3. I have learned not to violate the prime directive of Windows Thread
programming-"Though shalt not operate on a window from other than its
creating thread." Basically to use the Invoke method.

Some minor flaws remain, and I turn to you again for advice...

1. At the start of the operation, I changed the Cursor to
Cursors.WaitCursor, and I change it back to Cursors.Default after the
operation completes. But my Cursor changes almost immediately to the
Default cursor, even though the line instructing it to be set to
Default, is reached only later in the processing. Is this behaviour
changeable too ? I want to keep showing an Hourglass while processing
continues.

2. The retrieval operation seems to take longer than before. Is this
normal, or just a psychological reaction of mine ? :-)

Thanks again, folks,

Regards,

Cerebrus.

Feb 15 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.