.. _thread-model-label: A Thread-model for the CameraSDK ================================ In the code samples, a single thread has been used for the sake of simplicity. In reality, we recommended a multi-threaded approach. In this section, we suggest a thread-model for working with the CameraSDK. .. image:: thread-model.png :width: 75% :alt: A diagram of the how multiple threads handle separate tasks :align: center One possible thread-model is as follows: Create one thread to handle ``SdkEvents`` regardless of connected cameras (this is used to e.g. notice, when a camera is available to be opened). Additionally, create 3 threads per connected camera: 1. One to handle notifications (WaitForNotification – this includes both PropertyEvents and CameraEvents), 2. one to handle the reception of images (WaitForImage), and 3. one to handle LiveView (WaitForLiveView). Implementing this thread-model allows for the program to handle several blocking calls simultaneously, independently from each other. Thus, the threads do not have to wait on processes that may be slower to finish before they can execute the tasks (e.g. receiving an image before being able to capture a new one). When using multiple threads, you should implement clean-up procedures as well. These should close/release threads that are no longer needed. You can use the following method to release waiting threads held in this camera’s ``WaitForImage`` and ``WaitForLiveView`` methods: .. code-tabs:: .. include-tab:: ../../labels/cppWakeUpWaitingImageThreads :language: cpp :title: C++ .. include-tab:: ../../labels/csWakeUpWaitingImageThreads :language: csharp :title: C# To release the notification-thread, you use the following methods: .. code-tabs:: .. include-tab:: ../../labels/cppWakeUpWaitingThread :language: cpp :title: C++ .. include-tab:: ../../labels/csWakeUpWaitingThread :language: csharp :title: C# .. note:: Closing the camera will release all waiting threads for that camera, causing an implicit call to ``WakeUpWaitingImageThreads``.