From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple call to RunUserInterface & QuitUserInterface...

I'm aware that calling RunUserInterface & QuitUserInterface in different threads is not a good idea, but I have to do that.

I have some exported functions in a dll to load, display and discard panels. If I forget about the RunUserInterface & QuitUserInterface, it works fine. I may display/hide any number of panels in any sequence.

But the close control 'x' on the control bar doesn't respond to clicks, which looks quite strange. So I added RunUserInterface and installed QuitUserInterface callback respectively in the dll. As we can predict, that caused problems like these 2 links below describes:
http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=5065000000080000002C1A0000&USEARCHCONTEXT_C
ATEGORY_0=_318_&USEARCHCONTEXT_CATEGORY_S=0&UCATEGORY_0=_318_&UCATEGORY_S=0&UPostedFromTimeSearchArg_0=29&UPostedFromTimeSearchArg_1=8&UPostedFromTimeSearchArg_2=1999&UPostedFromTimeSearchArg_S=4&UPostedToTimeSearchArg_0=25&UPostedToTimeSearchArg_1=2&UPostedToTimeSearchArg_2=2004&UPostedToTimeSearchArg_S=4&USEARCHCONTEXT_TIER_0=2&USEARCHCONTEXT_TIER_S=0&USEARCHCONTEXT_QUESTION_0=RunUserInterface+QuitUserInterface+LoadPanel&USEARCHCONTEXT_QUESTION_S=0
http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=50650000000800000099AF0000&USEARCHCONTEXT_CATEGORY_0=_318_&USEARCHCONTEXT_CATEGORY_S=0&UCATEGORY_0=_318_&UCATEGORY_S=0&UPostedFromTimeSearchArg_0=29&UPostedFromTimeSearchArg_1=8&UPostedFromTimeSearchArg_2=1999&UPostedFromTimeSearchArg_S=4&UPostedToTimeSearchArg_0=25&UPostedToTimeSearchArg_1=2&UPostedToTimeSearchArg_2=2004&UPostedToTimeSearchArg_S=4&USEARCHCONTEXT_TIER_0=2&USEARCHCONTEXT_TIER_S=0&USEARCHCONTEXT_QUESTION_0=RunUserInterface+QuitUserInterface+LoadPanel
&USEARCHCONTEXT_QUESTION_S=0

Then how to display/hide a bunch of panels with the close control still working?

Many Thanks,
Echo
0 Kudos
Message 1 of 9
(3,949 Views)
My 2 cents worth:

I activate my (x) in the control bar by adding a callback to my panel.

int CVICALLBACK myXcallback (int p, int event,
void *c, int d1, int d2)
{
if (event == EVENT_CLOSE)
{
HidePanel(p);
}

return 0;
}

However, I also have multiple RunUserInterface(), QuitUserInterface() calls. I have inherited this code, and taking them out makes the panels not process events correctly (or not at all).
- I don't know if my memory leaks are caused by the RunUserInterface() repeatedly or not... I am trying to convert them to ProcessUserEvents() now, to see what that does.
0 Kudos
Message 2 of 9
(3,949 Views)
Echo,

It is not a good idea to have multiple calls to RunUserIterface(...), here is a document that explains this a bit further:
Why Do I Get General Protection Fault Errors When I Execute RunUserInterface( ) in Multiple Threads?


By default the panels will not close when you click on the "X"; as the other answer states you need to define a callback for the panel and in the EVENT_CLOSE you can hide it or discard it.

Please give this a try and let us know how this goes.

Regards,

Juan Carlos
N.I.
0 Kudos
Message 3 of 9
(3,949 Views)
I posted a simple example of this. All I do here is schedule a function to run in a different thread in the threadpool, where the function loads the panel, displays it, and then lets user quit if he needs to.

When you hit ok, a bunch of panels will load up on the corner ( overlapping ). You can close them one by one by clicking on the X.

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 4 of 9
(3,949 Views)
HidePanel only can't make the 'x' control work, that's why I have to use RunUserInterface() & QuitUserInterface(). The code have to be like below:

int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_CLOSE:
HidePanel(panel);
QuitUserInterface(0);
break;
}
return 0;
}

QuitUserInterface() is a must to activate the 'x' control.

Regards,
Echo
0 Kudos
Message 5 of 9
(3,949 Views)
Yes, it helps. Thanks a lot.

Regards,
Echo
0 Kudos
Message 6 of 9
(3,949 Views)
Well, I played with this for a bit and looks like you do need to have RunUserInterface ( or perhaps a loop with ProcessSystemEvents ) for each thread you spawn.

Excerpt from the CVI documentation topic "Panels and Multithreading "

You must discard a panel in the same thread in which you load or create it. Before a thread terminates, explicitly discard all panels you loaded or created in that thread.

Check out a shipping example on the correct why to set this up as well

..\CVI\samples\utility\threading\ThreadPool\MultiPanel\MultiPanel.cws

Bilal
Bilal Durrani
NI
0 Kudos
Message 7 of 9
(3,949 Views)
Lily,

Look at the following shipping example:

C:\.....\CVI\samples\utility\Threading\ThreadPool\MultiPanel

It does exactly what you are trying to do. Note that the example does call RunUserInterface on each thread spun. But that's because the example uses multiple panels and if a panel is created on a given thread, it has to be discarded on the same thread.

Good luck,
Azucena P.
National Instruments
0 Kudos
Message 8 of 9
(3,949 Views)
That seems quite promising. I'll try this later.

Thanks for all your help.

Regards,
Echo
0 Kudos
Message 9 of 9
(3,949 Views)