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
Stoitcho Goutsev (100) - 09 Mar 2006 14:32 GMT
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

Signature
HTH
Stoitcho Goutsev (100)
> Hi,
> Iam developing an application using windows forms as the gui. The
[quoted text clipped - 8 lines]
> Thanks
> Julia
Bob Powell [MVP] - 09 Mar 2006 18:43 GMT
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.

Signature
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.
> Hi,
> Iam developing an application using windows forms as the gui. The
[quoted text clipped - 8 lines]
> Thanks
> Julia