Page 1 of 1

PSJob not running for v5 Host (silent)

Posted: Tue Jun 11, 2019 9:31 am
by PXL_Posh
Product, version and build:
64 bit version of product: Powershell Studio 2019 v5.6.156
Operating system: 64 bit Windows 10 Enterprise

Using sychronized hashtable and xml with STA

The script will not generate the xml nor the csv.
In addition, I'm not seeing the additional window indicating the psjob is running.
I have plenty of error reporting but no errors are generated in the output window.

This runs without issue from ISE.
My settings are pretty basic:
no config file, no STA mode as that is already in the script, no impersonation nor runas.

I've tried all the Script Engines for v5 Host with the exception of service and Tray App.
issue_1.ps1
(3.91 KiB) Downloaded 73 times

Re: PSJob not running for v5 Host (silent)

Posted: Tue Jun 11, 2019 9:45 am
by davidc
[TOPIC MOVED TO WINDOWS POWERSHELL FORUM BY MODERATOR]

I recommend selecting a console host to debug the executable. The silent host suppresses all output, including errors.
I addition, if you are doing any asynchronous operations, you much make sure you wait for the operation to complete otherwise the script will terminate when it gets to the end.

Re: PSJob not running for v5 Host (silent)

Posted: Tue Jun 11, 2019 9:56 am
by jvierra
This looks to be part of WPF code. Are you trying to call a function in a WPF form?

Re: PSJob not running for v5 Host (silent)

Posted: Tue Jun 11, 2019 10:17 am
by PXL_Posh
Thank you for your reply davidc.

Unfortunately, I've tried a console host and nothing spits out. I tried again for the sake of testing and no errors.

I also ran the debug in powershell studio.

SAPIEN PowerShell V5 Host (Command line)

The receive-job has the -wait parameter which I hope is sufficient.

The script starts with "Please wait, contacting database..."
I've double checked the output window link and it matches correctly.

Re: PSJob not running for v5 Host (silent)

Posted: Tue Jun 11, 2019 10:17 am
by PXL_Posh
jvierra wrote:
Tue Jun 11, 2019 9:56 am
This looks to be part of WPF code. Are you trying to call a function in a WPF form?
Yes, I am calling the fuction in a WPF form.

Re: PSJob not running for v5 Host (silent)

Posted: Tue Jun 11, 2019 10:54 am
by jvierra
I went through you code. In a couple of minutes I threw out almost half as redundant or incorrect.

I suggest that you test each piece of code without a form. Be sure that you remove all unnecessary lines and take advantage of good PS coding style and standards. This will make the code more predictable and much easier to understand.

Note that 'jobs" do not have a window or a display. If the thread that the job is running on terminates the job will disappear. Running a job in a delegate will fail because the delegate has limited access to the WPF form and the session that executed the delegate call. An "[action]" is a delegate. It is intended to trigger events and to set properties and is not intended as a remote function executor.

Looking at your code I find it very hard to understand what you are trying to accomplish and why it has to be run as a delegate.