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
is it safe to use methods and properties inside a thread
-
AndreyZ
Re: is it safe to use methods and properties inside a thread
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.
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
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 ?
Code: Select all
<TIBCSQL>.Execute-
AndreyZ
Re: is it safe to use methods and properties inside a thread
In the situation you described it is safe to call the TIBCSQL.Execute method from the thread.