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.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

AfterUiMessageEvent Handler in .Net Console Application

Solved!
Go to solution

I need to execute a Sequence File with Processmodel in a .Net Console Application

 

Therefore I can't use any Form Control and need to do all by code

 

How can handle an event for each executed Step and retrieve its Properties (Name, Result, etc)?

 

TsEngine Object provides a UIMessageEvent, but I need AfterUiMessageEvent...

 

Thanks for your help

0 Kudos
Message 1 of 4
(4,166 Views)

If you want to use ApplicationMgr, you might need to create a hidden Windows Forms form on which to host it. I'm not sure if it works without being hosted on a form since it's an activex control. Having a hidden form with the control on it should be relatively trivial to do, and I think nothing prevents a console application from also using/creating Windows Forms windows.

 

Hope this helps,

-Doug

0 Kudos
Message 2 of 4
(4,152 Views)

Thanks for your reply,

I don't want to use any controls at all!

It has to be possible to enable ActiveX Communication without controls, otherwise it's bad design by NI

Smiley Frustrated

0 Kudos
Message 3 of 4
(4,138 Views)
Solution
Accepted by topic author kussy

1) Creating a hidden form to host the control is not hard. This is all that's required:

 

            System.Windows.Forms.Form hiddenForm = new System.Windows.Forms.Form();
            NationalInstruments.TestStand.Interop.UI.Ax.AxApplicationMgr appMgr = new NationalInstruments.TestStand.Interop.UI.Ax.AxApplicationMgr();
            ((System.ComponentModel.ISupportInitialize)(appMgr)).BeginInit();
            hiddenForm.Controls.Add(appMgr);
            ((System.ComponentModel.ISupportInitialize)(appMgr)).EndInit();

Your main function for the thread will also need the STAThread attribute (or if you create a new worker thread dynamically it should be set as using STA):

 

        [STAThread]
        static void Main(string[] args)

If you want UIMessages as events to work then you must have a window message loop somewhere in the thread, for example:

 

System.Windows.Forms.Application.Run(); // Or call a function that waits in a message loop for something.

 

You could do all of this in a worker thread instead of the main thread if you want the main thread free to do other things.

 

2) If you want to do something simpler and/or lower level, you don't have to use the ApplicationMgr at all, you can create the Engine directly and poll for UIMessages rather than using an Event (an event doesn't really make sense unless you are processing Window messages or using multiple threads).

 

You can do this as follows:

 

Engine engine = new Engine();
engine.UIMessagePollingEnabled = true;

// then to get messages when you want to, call:

engine.GetUIMessage();

 

Hope this helps,

-Doug

Message 4 of 4
(4,121 Views)