LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Need a way to safely exit program

We need a way to detect if a user close or ends our cvi application prematurely.

 

I can detect if someone kill the application using task manager.  However if my function completes the program does not end..

 

How do I get my program to continue once the thread is complete?  The below code shows how I am trying to test this.

 

#include <ansi_c.h>
#include <utility.h>
#include <userint.h>


int CVICALLBACK EventFunctionName (int panelOrMenuBarHandle, int controlOrMenuItemID, int event, void *callbackData, int eventData1, int eventData2)
{
if (event==EVENT_END_TASK)
{
if (ConfirmPopup ("Shut Down Detected", "Power to module turned off")!=1)

{
return -1;
}
}
return 0;
}

 

int CVICALLBACK InfinateLoop(void *functionData)
{
int count = 0;

while (1){
printf("Count is: %d\n", count);
Delay(1.0);
count++;
if(count == 5){
return 1;
}
}
return 0;
}

 

int main(int argc, char *argv[]){
int functionId;

InstallMainCallback (EventFunctionName, 0, 0); //EVENT_END_TASK

CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, InfinateLoop, NULL, &functionId);

RunUserInterface ();

}

 

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

Hey Malcrow,

 

I'm not exactly sure what you are trying to do.

 

Are you trying to allow your program to complete once the user tries to end it?  Or are you just trying to detect that a user is closing the program?

 

If you want the program to finish, you may need to look into swallowing the event.

 

Here are some links that may help:

Using Callback Functions to Respond to User Interface Events

EVENT_END_TASK

Swallowing Events

Regards,
Jake G.
National Instruments
Applications Engineer
0 Kudos
Message 2 of 3
(2,542 Views)

Jake,

 

Thanks for the reply.  I have read some of those pages already.

 

Yesterday I used:

 

CmtWaitForThreadPoolFunctionCompletion (DEFAULT_THREAD_POOL_HANDLE, functionId, OPT_TP_PROCESS_EVENTS_WHILE_WAITING);

 

Using this line I am able to start the thread,  show the data and then exit.  Also it will detect if someone tries to close the program and runs my code.  I will be implemnting this in our project and testing it later this week.

0 Kudos
Message 3 of 3
(2,529 Views)