Timer Thread b

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

Guest

Hi,
I have a query that takes over a minute to execute so I want to put a timer
on the form while its running. Both procedures work individually, but when I
try to create a thread i get this error:

* Additional information: Controls created on one thread cannot be parented
to a control on a different thread.

Which should be the main thread and which should run in the background?
Right now the query is attempting to run in the background but as soon as I
set the table styles for the datagrid;
dgDisplay.TableStyles.Add(dgts)

i receive the error (*). Any suggestions?
Thanks
 
Hi,

You are violating Rule No. 1 of Multi-threading in .NET :

"Thou shalt not operate on a control from other than its creating
thread."

This simply means that controls must not be updated from other threads,
other than the UI Thread.

So, to get around this problem, use the BeginInvoke method...

See these articles for more information :

<http://www.knowdotnet.com/articles/fillingdatagridfromthread.html>
<http://msdn.microsoft.com/msdnmag/issues/03/02/Multithreading/>

Hope this helps,

Regards,

Cerebrus.
 
Back
Top