LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating A Panel in A new thread then closing

I create a panel on startup in its own thread then if the user clicks a button, I create another thread using the same function as before(pulls up a duplicate panel). This all works fine until the 14th press of the button. Pressing the button is basically a refresh but it closes the panel and then reopens it. It seems like it will not create another thread. Is there some way to delete the thread when I refresh? I am using DIscardPanel() when closing.

0 Kudos
Message 1 of 2
(810 Views)

It is always a good policy to dispose of resources when you do not need them anymore, including threads. Discarding the panel releases the memory associated with it but it does anything to the thread that created the panel.

The minimum you must do to properly terminate a thread is to:

  1. Signal the thread to terminate
  2. In the main thread call CmtWaitForThreadPoolFunctionCompletion () to monitor thread closing
  3. When the thread terminates call CmtReleaseThreadPoolFunctionID ()

But remember that simpler is better: you may want to reconsider your framework in order to discriminate whether your close-thread-and-create-a-new-one is the best approach to your situation.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(792 Views)