prevent windows form from "hang"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Iam developing an application using windows forms as the gui. The
application is doing some heavy database work. While this work is done (I use
separate threads for this) I would like to print some information in the gui
but I dont know how to do, because it seems like the gui is locked? What can
I do to make this work?

Thanks
Julia
 
Julia,

You can't modify the GUI from a worker thread. That has been asked many
times. You need to marshal the execution to the GUI thread and make the
modifications there; to do that you need to use Control.InvoleRequired and
Contro.Invoke memebers.

For more info:
http://msdn2.microsoft.com/en-us/library/ms171728.aspx
 
In addition to Stoitcho's suggestion you can use the same method to invoke a
method in your gui thread that just calls Application.DoEvents().

You could even run this call from a System.Timers.Timer that is running
while your other worker-thread is getting the database info. Invoke would
still be necessary though in either case.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top