Solved

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

Posted on 2013-06-06
7
1,352 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now