Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I don't quite know how to solve this. My Googling obviously was obviously not using the correct terms.

I have just built a Ray Tracer (works very well if I don't say so myself). Obviously the
C#
Image Draw() {}
function is a hefty load and can take anywhere between 1 sec -- many days depending on the scene


When I call the draw function I want the user to know it has begun processing by displaying Action: Rendering and when its complete I want it to display Rendering complete

This is all handled by a render button, which calls this when clicked
C#
action_label.Text = "Action: Rendering...Please Wait!";
Invalidate(); //I hoped this would work
viewport.Image = Scene.Draw();
action_label.Text = "Action: Rendering Complete!";

I hoped calling invalidate just after setting the text would work. All that happens is it shows Rendering complete.

How can I get it to update the text on the form before it starts to process?
Thank you all in advance :)
Posted
Comments
Keith Barrow 30-Jul-11 14:33pm    
Is the Scene.Draw executing spinning off the long-lived stuff to another thread? If so this is exactly what you'd expect - and need, blocking the UI thread is bad for the user. If you do spin this off, you need to update the UI in reaction to the long-lived process finishing somehow, the details are implementation specific.
Thomas.D Williams 30-Jul-11 14:51pm    
So your suggesting using threads. I've never used threads before. Will it be a big learning curve?
Currently its just a class, no threads that I have made
Keith Barrow 31-Jul-11 5:56am    
Sorry, went to bed. Luckily Manas Bhardwaj has provided you with your answer!

1 solution

You might want to have a look at BackgroundWorker [^]
 
Share this answer
 
Comments
Thomas.D Williams 30-Jul-11 15:01pm    
Looks like the right tool for the task :) Thank you
Manas Bhardwaj 31-Jul-11 5:47am    
glad it helped!
Thomas.D Williams 31-Jul-11 6:43am    
I've now got it working. It even shows percentage progress as it goes. Had to add a little to my ray tracing class to report how much it had done + a timer to check the progress every second :) Thanks for your help
NandaKumer 30-Jul-11 16:48pm    
nice answer
Manas Bhardwaj 31-Jul-11 5:47am    
thnks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900