Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WinForm question 2

Status
Not open for further replies.

DeveloperJr

Programmer
Mar 10, 2007
25
US
I have a form Form1 that instantiate an object Obj1 which in charge of doing some lengthy process from within a method called Obj1.method1

What I need is to be able to communicate the progress status from Obj1.method1 to Form1. For that purpose, I wrote a method in the form that updates the progress bar, defined a delegate in the form, pass the delegate to the Obj1.method1, use delegate inside the method to update the progress bar. The same old stuff, it works great and the progress bar tells me where I am. But, if I hide the form, my screen saver kicks in, open another program over the form or even click on my form, the form blanks out along with the progress bar. How can I avoid that? Can I instantiate the Obj1 on a separate thread?
Please advice

 
Typically you would want to do your lengthy method on a separate thread and Invoke() the change back to your GUI thread.

If you want to try a quick solution in the meantime, everytime you udpate your progress bar try Application.DoEvents();

See how that works for you.
 
Thanks for your reply. I tried to invoke the method via a delegate and I used BeginInvoke() but the GUI did not refresh. Can I instanciate an object on its own thread?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top