views:

619

answers:

5

This is a common problem for all the developer, i am looking for best solution to make windows forms UI responsive.

I have an Animated GIF file to show progress of my calcuation on windows form. I took a picture box control and placed animated gif into that. now when my calcuation starts - the animaged gif freeze. i want the reverse, the animation should be visible when i am running calcuation.

Any to the point thoughts ? simple solution to display a progress to the user while doing complex calculations behind the scene ?

My app is single threaded appliation, and want simple solution, not looking for multi-threads, or background worker kind of technologies.

Any help ?

+3  A: 

Application.doevents

You place it in the loop. It gives the UI the time to do its things.

Ikke
+3  A: 

Well, the only real way to do 2 things at once (like do calculations, and still keep responsive) is to use threads. If you won't want to explicitly use threads, then check to see if there are any asynchronous calls you can use to do it in the background. Aside from that, do a lot of Application.DoEvents calls wherever you do lots of work.

Danimal
+8  A: 

Multiple threads would be my recommandation. A bit messy first time you try ;)

Simplest model: One thread for the GUI, and one thread for whatever work you need to do.

Check e.g.: http://msdn.microsoft.com/en-us/magazine/cc300429.aspx

Erik
Problem is that you have to work with delegates and invoke to make changes at the ui from the worker thread.
Ikke
Yes. And? Once you know how, it's no longer a problem.
Erik
Well, sometimes you want to seperate the logic from the view. I've worked on a class which simplifies the use of sockets. It uses a thread to look for data. But i can't just dispatch an event that data is available, and then update the ui in that event.
Ikke
+2  A: 

I'm going to have to site Jeff on this one:

Coding Horror: Is DoEvents Evil?

bsruth
+1  A: 

"simple solution to display a progress to the user while doing complex calculations behind the scene ?"

"not looking for multi-threads, or background worker kind of technologies."

Which of those wishes is more important to you? You'll have to choose one or the other.

Windows programmer