Solved

c# 2010 winforms update animated gif without using application.doevents

Posted on 2013-06-06
7
1,373 Views
Last Modified: 2013-06-07
HI

I have an application which has a few processes which can take some time to complete, especially over the network.  So to give the user some feedback, I have a hidden panel, which I make visible once the process starts, and remove it from the screen when the process finished... in the panel I have a animated gif (ajax load type) and a message saying the system is thinking...

trouble it, the animated gif doesn't update without doing an application.doevents (putting this in makes the process take twice as long)

so is there any way for me to refresh the animated gif so that the animation will play fluid?


Cheers

CD
0
Comment
Question by:cycledude
  • 3
  • 2
  • 2
7 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39228120
>>so is there any way for me to refresh the animated gif so that the animation will play fluid?


Yes, but you might not like it.
The DoEvents is to force the main thread to process any waiting messages.  Actions that take a long time to complete (such as yours) really should be done in a separate thread to allow the main thread to work normally.  So, to make your app work 'correctly' you should do the process in another thread.  (It shouldn't be too much more recoding but definately more than just adding a DoEvents in a loop somewhere).
0
 

Author Comment

by:cycledude
ID: 39228137
Thanks andy

How do I go about setting the process to run in a separate thread?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39228148
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 13

Expert Comment

by:Naman Goel
ID: 39228151
There are so many ways to achieve this, the easiest and robust one is by using backgroundworker, move your time consuming code in dowork event handler.

The other was to use Delegate

create a method for your time consuming method and call it in using BeginInvoke method.
0
 

Author Closing Comment

by:cycledude
ID: 39228154
thanks andy, thats great ;o)
0
 

Author Comment

by:cycledude
ID: 39228308
sorry naman_goel, I didn't see your response before I awarded the points, otherwise you would have had a share, because your suggestion looks like it work too..
0
 
LVL 13

Expert Comment

by:Naman Goel
ID: 39228320
:) .
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question