Freddy1990
2007-11-05 17:56:23
Hello there,
I've recently been wondering what causes a series of inexplicable errors which occur while running a script. Now I've become aware of the fact that this is due to the script engine being thread-unsafe. This basically means that when accessing something in anotehr thread there's a change (which is higher for writing values than reading them) that access violation errors will occur. This happens most commonly when accessing the GUI thread. This means most of the form interactions and GetSelf/GetApplication usage (where any form would be accessed, not for like MessageBox). This can be resolved by using the ThreadSafeCall function. For example, when you wish to place a value in a TEdit on a form created by your script, it is best to create a function which places the value into it and a function using the ThreadSafeCall function to access it. Though errors will not occur every time a property is read or written to, the chance does exist and it might occur on later times. (This is also the reason why form initialization functions are ran trough ThreadSafeCall, it writes many values to the form, which makes it a high-risk situation).
I'm currently planning on attempting to build thread-safety into the scriptengine, but until I do it's suggested to use ThreadSafeCalls as much as possible, ESPECIALLY when writing values to form controls.
(NOTE* The movetotray bug is not caused by this)
I've recently been wondering what causes a series of inexplicable errors which occur while running a script. Now I've become aware of the fact that this is due to the script engine being thread-unsafe. This basically means that when accessing something in anotehr thread there's a change (which is higher for writing values than reading them) that access violation errors will occur. This happens most commonly when accessing the GUI thread. This means most of the form interactions and GetSelf/GetApplication usage (where any form would be accessed, not for like MessageBox). This can be resolved by using the ThreadSafeCall function. For example, when you wish to place a value in a TEdit on a form created by your script, it is best to create a function which places the value into it and a function using the ThreadSafeCall function to access it. Though errors will not occur every time a property is read or written to, the chance does exist and it might occur on later times. (This is also the reason why form initialization functions are ran trough ThreadSafeCall, it writes many values to the form, which makes it a high-risk situation).
I'm currently planning on attempting to build thread-safety into the scriptengine, but until I do it's suggested to use ThreadSafeCalls as much as possible, ESPECIALLY when writing values to form controls.
(NOTE* The movetotray bug is not caused by this)