473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Unresponsive UI during lengthy operation ?

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
6 2837
Just to add a question...

Is Multi-threading the only answer

Regards,

Cerebrus.

Feb 15 '06 #2

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
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
> 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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
0
by: Marco Auday | last post by:
I need to associate items in two listviews. I have got the drag-and-drop operation to perform as I wanted. However, I would like the items in the target listview to be highlighted when the mouse...
4
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the...
14
by: Brian Keating EI9FXB | last post by:
I wonder can anyone reccomment a solution to this problem. Let me explain, I've services running on my system, my application receives diagnostic messages from these services, what i want to do...
3
by: mudman | last post by:
I'm running Visual Studio.NET and am experiencing a problem during debugging (i assume this will also be the case during normal operation). If the variable "test" is a double and "denom" a finite...
0
by: Samuel R. Neff | last post by:
I have a typical TreeView/ListView combo and can drag from the ListView to the TreeView. I'd like to select the TreeView node that is the target of the drag operation as the ListView items are...
5
by: Jonah Bishop | last post by:
I'm developing a photo album web application for use on a web site, and I'm running into a problem with lengthy operations. My application allows the user to import a number of images at once into...
13
by: michael sorens | last post by:
I have a lengthy sequence of operations that are executed and reported on in a status window in a Windows Form application. Some work is done by background threads but other work is not. I am...
2
by: Dmitry Teslenko | last post by:
Hello! I'm using os.popen to perform lengthy operation such as building some project from source. It looks like this: def execute_and_save_output( command, out_file, err_file): import os ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.