NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

ApplicationMgr shutdown returns 0

ApplicationMgr returns 0 (False) when the OnClose event is triggered. Anyone know what may cause this?
0 Kudos
Message 1 of 10
(5,188 Views)
I should also mention that I am getting the following exception

"First-chance exception in server.exe (TSUI.DLL): 0xC0000005: Access Violation"

After OnClose the ApplicationMgr sends OnExitApplication_ApplicationMgr event that contains the following lines of code:
{
PostQuitMessage(0); //for my message loop (modeless dialog)
EndDialog(0);
}

Here's where I get the exception mentioned above. Am I missing something? Why is the ApplicationMgr failing to shutdown? I tried calling it again within the OnExitApplication event and it still fails.
0 Kudos
Message 2 of 10
(5,184 Views)
Application.Shutdown returns FALSE (0) if there are any tasks that must complete asynchronously before the application can exit. If so, the application manager waits for these tasks to complete and then sends the ExitApplication event. These tasks include but are not necessarily limited to waiting for running executions to terminate and running sequence file unload callbacks.

I don't know why your application is crashing. The example operator interfaces don't crash on exit. Assuming you started from one the examples, the simplest way to find the problem might be to use your source control system to roll back the changes you have made until you find the change that introduced the problem.

If your application source code can be zipped up without any dependencies such that others can readily build and run a debug version of it, another option would be to post your application here or send it to NI support for a diagnosis. Of course, the simpler the application you post that reproduces that problem, the easier it will be for someone to help you.
0 Kudos
Message 3 of 10
(5,184 Views)
Here it is. It is a stripped down version from what it is supposed to be. In essence, it's a win32 console application creating a thread that does some MFC initialization then creates a modeless dialog with all the TS OI controls.

Unzip the folder to your desktop.

The only dependencies are the files tsutilCPP.cpp & tsutilCPP.h (I am assuming they are in their default location). Make sure they exist in the project and build.

The OnClose/OnExit events are in TestExecDlg.cpp. The code in Fakethrd.cpp/.h I found here: http://www.michaelmoser.org/tip3b.htm for accessing MFC Objects from Non-MFC Threads.

If there any questions, don't hesitate to email me directly.

I really appreciate the help!!
0 Kudos
Message 4 of 10
(5,167 Views)
I have found a workaround, but need to investigate further to know why exactly this is happening.

It appears that if the Engine reference is released before the UI controls get released, the exception occurs. This leads me to believe that the destructor for the UI controls counts on an engine reference being valid. To solve the problem, I ensured the engine was the last item cleaned up.

I added the following destructor:

CTestExecDlg::~CTestExecDlg()
{
mApplicationMgr = NULL;
mSequenceFileViewMgr = NULL;
mExecutionViewMgr = NULL;
mFilesCombo = NULL;
mOpenFileBtn = NULL;
mSequencesCombo = NULL;
mCloseFileBtn = NULL;
mEntryPoint1Btn = NULL;
mEntryPoint2Btn = NULL;
mRunSelectedBtn = NULL;
mExecutionsCombo = NULL;
mCloseExecutionBtn = NULL;
mSequenceView = NULL;
mBreakResumeBtn = NULL;
mTerminateRestartBtn = NULL;
mTerminateAllBtn = NULL;
mLoginLogoutBtn = NULL;
mExitBtn = NULL;
mStepIntoBtn = NULL;
mReportView = NULL;
}

This ensures the engine is the last item released. I will investigate this further to determine the real cause.

Allen P.
NI
0 Kudos
Message 5 of 10
(5,143 Views)
Perfect. That's a good idea.

I am still getting ahn exception though when debugging (inbetween loading Dlls). There's also the following warnings:

Warning: calling DestroyWindow in CWnd::~CWnd; OnDestroy or PostNcDestroy in derived class will not be called.
Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called.

Could it be that I am not destroying the dialog properly? It is a modeless dialog so all the clean up is not done automatically. I am probably missing something there as well.
0 Kudos
Message 6 of 10
(5,137 Views)
I was getting a bunch of similar errors. My presumption is that the automatic cleanup that is normally happening is not happening in your OI.

For the following warning:

Warning: calling DestroyWindow in CWnd::~CWnd; OnDestroy or PostNcDestroy in derived class will not be called.

I found the following article on Microsoft's website.

I fixed the problem by calling
mApplicationMgrCWnd.DestroyWindow();
mSequenceFileViewMgrCWnd.DestroyWindow();
mExecutionViewMgrCWnd.DestroyWindow();
mFilesComboCWnd.DestroyWindow();
// more lines for each CWnd object I have.


For the other warning, I solved by adding the following line in the destructor.
Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called.

this->DestroyWindow();

Hope this helps!

Allen P.
NI
0 Kudos
Message 7 of 10
(5,085 Views)
I found a better solution for you.

If you create your dialog on the heap rather than the stack, you can control the deletion.

So instead of

CTestExcDlg abc;

you should do

CTestExecDlg * abc = new CtestExecDlg();
.

At the end of that code block, call

delete abc;

You can remove the destructor for the Dialog class as well.

Hope this helps!

Allen P.
NI
0 Kudos
Message 8 of 10
(5,064 Views)

I should add one additional point.  Make sure that you delete the Dialog class before you call OleUninitialize.

0 Kudos
Message 9 of 10
(5,052 Views)
We have the day off here today. I will give it a try first thing Monday morning and let you know if anything comes up. 
 
Thank you very much for your help Allen. I really appreciate it.
 
Dia
0 Kudos
Message 10 of 10
(5,039 Views)