08-31-2024 08:26 PM
Does anyone have an example of calling a non-modal WPF window. I'm able to successfully call a modal window but hangs TestStand UI until the window is closed.
I've seen the out-of-box example (below) that does what I need but need to use WPF not WinForms.
C:\Users\Public\Documents\National Instruments\TestStand 2019 (32-bit)\Examples\Demos\Computer Motherboard Test\DotNET
Any help is appreciated. Thx
Solved! Go to Solution.
09-03-2024 02:05 PM
Greg,
1) Although I hit this in the past with ActiveX based UIs in a DLL, so may be an issue for WPF but easy to test. All TestStand execution threads are initialized as MTA (multi-thread apartment) and at least for older UI frameworks, STA (single-) threads were required. You can easily test this by moving your step that displays your dialog into a separate sequence, and then call the sequence using a Sequence Call step with Execution Options set to 'Use New Thread', and its Advanced Settings configured with 'Use Single-Threaded Apartment' enabled.
2) Also take a look at this older forum post that has some code snippets: Re: Calling WPF from TestStand
09-03-2024 02:17 PM
Thanks @Scott_Richardson for response. I will review your approach.
I did come across the link before and I have something setup similar to its code snippet. However, this is around modal (ShowDialog) where it locks up TestStand until I click a button in my window to close. Need to be able to still click stuff in TestStand (like viewing reports and such) along with minimizing TS to interact with other Windows things (desktop, etc.).
Thanks again.
09-04-2024 11:29 AM
Greg -
Got it, the modality is owned by the WPF code so how you are displaying the panel needs to be understood and likely changed, which is not my domain. There are ways to make a window top-most, so not sure if you want to look at that as well.
If you want TestStand to be able to pause an execution while the window is open and auto close if the execution is terminated or complete, there are ways of doing this, see non-WPF examples here:
09-04-2024 12:20 PM
Hi Scott,
I had some time to try out your suggestion, about a separate sequence thread with STA set, and does appear to work. It is not ideal as it would be nice to just have a step that calls the Show (or similar) method without the extra supporting logic. The disadvantage is being required to do this for any/every time of WPF window needed to display.
I'm going to keep this thread open (pun intended 🤣) in case there are some others that see and want to chime in.
Thanks again on help and, at least, a working option. 👍
09-05-2024 07:42 AM
Finally figured it out. Need to remove the TestStand engine modal logic, but still call ShowDialog() method on the window control so it will halt on the step until closed and also allow to continue interacting with main TestStand UI.
09-05-2024 11:41 AM
Simple solution, thanks for posting.