LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Child panel from a different thread hangs application

Hello,

 

I have TestStand sequence that calls an CVI-dll, that displays some text, graphics and has a few buttons.

TestStand calls this DLL in MTA by default.

In order to display an ActiveX Control on the DLLs mainpanel, I create a new thread pool inside this DLL and open a new thread in STA containing a panel with the mentioned ActiveX Control.

So far it works well, as long as both panels (the MTA-panel and the ActiveX Control STA panel) exist separately. (Two panels on different positions on the screen).

 

But actually I don’t want the AxtiveX Control panel to be separated from the mainpanel, so I have tried to make it a child of the mainpanel with SetParent (from SDK), called with PostDeferredCallToThread in a Callback.  In fact it works but only until the mainpanel reaches RunUserInterface(). At this point the whole application hangs (including TestStand).


This is what I have done:


mainpanel:
 

{

   ...

   mainthreadID = CmtGetCurrentThreadID ();

   CmtNewThreadPool (50, &poolHandle);

   CmtScheduleThreadPoolFunction (poolHandle, (ThreadFunctionPtr)CreateActiveXCtrl, 0,

                                      &threadID);

   ...

   RunUserInterface()

   ...

}

 

ActiveXControl panel:
 

int CVICALLBACK CreateActiveXCtrl(....)

{

 ...

CA_InitActiveXThreadStyleForCurrentThread (0, COINIT_APARTMENTTHREADED);

...

pHandle = NewPanel (...);   

NewActiveXCtrl(...);

...

PostDeferredCallToThread ((DeferredCallbackPtr)MakeChildPanel,0, mainthreadID);

...

}


void CVICALLBACK MakeChildPanel (void *callbackData)

{

                SetParent((HWND)actXPanel, (HWND)mainPanel);

}


Does somebody have an idea how to solve this case? And what’s the reason for this behaviour?

It would be also fine to include the ActiveXControl directly to the mainpanel, but I guess it doen't work because of the mainpanel being in MTA!?!

 

Mathias

0 Kudos
Message 1 of 2
(3,265 Views)

Mathias,

First, the CVI user interface library is not designed to work in conjunction with the Windows SDK.  Some SDK functionality will work OK, but there are many ways that SDK functions can interact with the CVI user interface library that will cause problems, crashes, hangs, etc.  It is not suprising that your call to SetParent caused problems.  You should use the 'Parent Panel Handle' parameter of NewPanel or LoadPanel to setup the parent/child relationship between your panels.

Second, the CVI user interface library requires that parent panels and child panels be created in the same thread.  This is stated in the CVI help in the following topic:

Library Reference>>User Interface Library>>Multithreading>>Multithreading Restrictions>>Panels and Multithreading

Third, my recommendation would be to create your main panel in the STA thread along with the child panel.  This should solve your problem.
 
Fourth, you mentioned previously that you might want to create your panels once in one step of a TestStand sequence and reuse the panels during multiple other steps of the sequence without recreating them each time.  I'm pretty sure that the ActiveX control will have an affinity for the particular STA thread you used to create the control.  This means you would probably need to use that same STA thread each time a sequence step displays the panels.  There are multiple ways you could do this, but one of the simplest would be to create your own thread pool that you use when creating the panels.  You could configure this thread pool to only have one thread and you could keep the thread pool handle around between sequence steps as a global in TestStand.  You would also store the panel and control handles as globals in TestStand.  When you have a sequence step that will display the panels, you would use the TestStand MTA thread to schedule a function on the thread pool stored in your global.  This function would use the panel and control handles stored in the globals to display the panels and run the UI.  When you were done using the panels, you could have a sequence step that discards the panels and cleans up the thread pool.
 
I hope that helps.
 
-Jeff
 
Message 2 of 2
(3,228 Views)