Page 1 of 1
is it safe to use methods and properties inside a thread
Posted: Tue 07 May 2013 22:33
by inageib
Hi,
I want to ask is it safe to call methods and read or change properties values of components like TIBCQuery, TIBCSQL, TIBCStoredProc, etc... from inside a thread other than the main app thread ?
Thanks
Re: is it safe to use methods and properties inside a thread
Posted: Wed 08 May 2013 13:18
by AndreyZ
Hello,
You can safely read properties, but writing properties and calling methods may cause numerous errors which are hard to trace. For example, if you use some code in the main thread that depends on some property value, and at the same time you change this property value in another thread, the code in the main thread may have an unexpected behaviour. The same applies to calling methods. Therefore, you should not access the same component from different threads. If you want to do this, you should ensure thread safety on your own.
Re: is it safe to use methods and properties inside a thread
Posted: Fri 10 May 2013 23:49
by inageib
I am asking specially if I called execute from within a thread
But also in the main thread I use execute with same component but both not called at same time, as the user need to open a form and press a button in this time the first thread would be finished executing. in addition I can check it the thread is terminated or not. do you think in this case a conflict may still occur ?
Re: is it safe to use methods and properties inside a thread
Posted: Mon 13 May 2013 13:32
by AndreyZ
In the situation you described it is safe to call the TIBCSQL.Execute method from the thread.
Re: is it safe to use methods and properties inside a thread
Posted: Tue 14 May 2013 16:32
by inageib
Thanks Andrey
Re: is it safe to use methods and properties inside a thread
Posted: Wed 15 May 2013 10:05
by AndreyZ
I am glad to help.