Threaded subroutines and Objects

skipper

Member
Licensed User
Just a question about Threads.

May I use inside a Treaded soubroutine an object created in the App_Start (eg. SqlConnect.New1) or should I create the object inside the threaded subroutine and release it before returnig to the main thread?

Many thanks

Mimmo
 

agraham

Expert
Licensed User
Longtime User
The only thing you must NOT do in a Thread is to do anything that affects a GUI object, that is Forms and Controls, as that may cause a crash. Thread events are there to help out with this as events run on the main GUI thread so you can effectively access GUI elements from a thread by using a thread event.

All other objects have no thread affinity and may be used as required. However you may need to be careful that the main thread and any threads you create do not try to use the same object at the same time. Sometimes it is OK, other times it is not, it depends upon your program and the objects in question. Use the RunLocked methods to ensure safe access to shared resources by separate threads.
 

skipper

Member
Licensed User
Many thanks Agraham,
your tips are precious! About the UI, I was already warned (the help and the samples state that in a clear manner). I was wandering about Objects.

I'll double check in my app about using at the same time (main thread and threaded subroutines) Objects created in the Main thread.

Thanks again
Mimmo
 
Top