Threaded subroutines and Objects

Discussion in 'Questions (Windows Mobile)' started by skipper, Jan 2, 2009.

  1. skipper

    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
     
  2. agraham

    agraham Expert Licensed 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.
     
  3. skipper

    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
     
  4. agraham

    agraham Expert Licensed User

    On a nice day I wander around my Objects too :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice