Using the threading library lockflag object

kolbe

Active Member
Licensed User
Longtime User
I want to make sure I understand the proper use of this object.

Lockflag.Wait and Lockflag.Reset should be used around all the instances of the global variables used in a non GUI thread event as well as the GUI thread event.

In other words, if I use the global var_z in the sub called by thread.start, every time I use var_z in the whole entire project I need to surround it by Lockflag.wait and Lockflag.reset.

This doesn't apply to control objects because they always run in the GUI thread when called by thread.firethreadevent.

Thanks
 

agraham

Expert
Licensed User
Longtime User
Lockflag.Wait and Lockflag.Reset should be used around all the instances of the global variables used in a non GUI thread event as well as the GUI thread event.
Yes if you are reading and changing it and there is a possibility of another thread also changing it. If you are only reading it probably not but its doesn't hurt to lock it even then and will serve to remind you that it is used across threads.
This doesn't apply to control objects because they always run in the GUI thread when called by thread.firethreadevent.
If by control object you mean GUI Controls like Buttons etc. then that is correct. As events always run on the GUI thread you don't need to lock any access to Controls by event code, or even access to global variables by an event.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…