GUI Script Hang with specific build engine.

Support for all customers who have purchased a SAPIEN PowerShell Studio product license. This forum does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
milindnaphade
Posts: 10
Joined: Sun Mar 03, 2013 12:44 pm

GUI Script Hang with specific build engine.

Post by milindnaphade » Sat Jul 28, 2018 5:08 am

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PowerShell Studio, 5.5.153_062918_x64
32 or 64 bit version of product: 84 bit
Operating system: Windows 10
32 or 64 bit OS: 64 bit

*** Please add details and screenshots as needed below. ***

I am working on a GUI script that has a code block that initiates an Azure storage blob copy and then shows an update about the percentage completion. The issue I am facing is that when the GUI script is compiled with Windows Forms as a build engine, the cmdlet Start-AzureStorageBlobCopy hangs.
There are no errors thrown. Everything works okay while running the script in debug mode in the IDE. On the other hand, if the script engine is set to Windows Application, everything works okay.
Could someone help? It is

User avatar
Alexander Riedel
Posts: 6685
Joined: Tue May 29, 2007 4:43 pm

Re: GUI Script Hang with specific build engine.

Post by Alexander Riedel » Sat Jul 28, 2018 6:08 am

Did you try enabling STA mode when packaging with the Forms engine?
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
milindnaphade
Posts: 10
Joined: Sun Mar 03, 2013 12:44 pm

Re: GUI Script Hang with specific build engine.

Post by milindnaphade » Sat Jul 28, 2018 8:15 am

Yes. The Use STA Mode (Recommended for GUI Scripts) is checked by default.

Even Windows Application as build engine would be perfect for me as far someone could suggest a way to hide a console Window that pops up at the time of compiled EXE execution.

User avatar
Alexander Riedel
Posts: 6685
Joined: Tue May 29, 2007 4:43 pm

Re: GUI Script Hang with specific build engine.

Post by Alexander Riedel » Sat Jul 28, 2018 9:11 am

Ok, now I am confused. If you package (its not a compiler) for Windows Application, there should be no console.
Maybe we should see some screenshots of the settings and what you see when you run it.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
milindnaphade
Posts: 10
Joined: Sun Mar 03, 2013 12:44 pm

Re: GUI Script Hang with specific build engine.

Post by milindnaphade » Sat Jul 28, 2018 9:27 am

Thanks for the correction. Yes, it is the packager.
When Windows Application is selected as a Packager. It renders a pop-up console as shown in the below screenshot.
Image

and here are the packager settings

Image

User avatar
Alexander Riedel
Posts: 6685
Joined: Tue May 29, 2007 4:43 pm

Re: GUI Script Hang with specific build engine.

Post by Alexander Riedel » Sat Jul 28, 2018 12:45 pm

Ah, yes, that is not a console. That is the actual host window. I am not sure why this one would work and the forms one would not, but I will look at the code and see what I can find out.

Try this in your code, best probably in your event handler when you show YOUR form.
$Window = $SAPIENHost.GetMainForm()
$Window.Visible = $false

This will only have an effect on the packaged executable. It might not work. It's just an experiment.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
milindnaphade
Posts: 10
Joined: Sun Mar 03, 2013 12:44 pm

Re: GUI Script Hang with specific build engine.

Post by milindnaphade » Sat Jul 28, 2018 9:14 pm

Well, that did not work

Code: Select all

Method invocation failed because [.] does not contain a method named 'GetMainForm'.
At line:783 char:3
+         $Window = $SAPIENHOST.GetMainForm()
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
The property 'Visible' cannot be found on this object. Verify that the property exists and can be set.
At line:784 char:3
+         $Window.Visible = $false
+         ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
Any other options. If it helps, the whole code worked just fine until a few days ago. I guess I am seeing a lot of issues after updating the PSStudio version to 5.5.153_062918. On the other hand, degrading the PS Studio version does not help any longer.

User avatar
Alexander Riedel
Posts: 6685
Joined: Tue May 29, 2007 4:43 pm

Re: GUI Script Hang with specific build engine.

Post by Alexander Riedel » Sat Jul 28, 2018 9:42 pm

As I said, it might not work. The Forms engine has not really changed for quite some time, and since it works in the other host and while running it from PowerShell Studio there is likely something else at play.
It is quite possible and it would not be the first time that a Windows Update or a framework update screwed something up.
I will investigate on Monday.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
milindnaphade
Posts: 10
Joined: Sun Mar 03, 2013 12:44 pm

Re: GUI Script Hang with specific build engine.

Post by milindnaphade » Sun Jul 29, 2018 4:17 am

Excellent. Thank you for the help.
BTW, I could work around the issue by using something like below:

Code: Select all

Add-Type -Name win -MemberDefinition '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);' -Namespace native
	
	[native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle,0)
With this, the host process won't close upon form closing though. So I added another piece of code on Form Closed event.

Code: Select all

$CurrentProc = [System.Diagnostics.Process]::GetCurrentProcess()
	$CurrentProc.Kill()
I definitely have adequate measures in place to prevent any data loss before killing the host process. If you believe an update would have messed up things (I agree that could be a possibility. Updates are known to mess up things quite often :-P) I am happy to provide machine information with all the configuration settings. It would at least help avoiding issues for others :-)

User avatar
Alexander Riedel
Posts: 6685
Joined: Tue May 29, 2007 4:43 pm

Re: GUI Script Hang with specific build engine.

Post by Alexander Riedel » Sun Jul 29, 2018 9:41 am

Yeah, that really is a hack so to speak :-)
I will look what the differences are because it really puzzles me why one engine would work and not the other.
Alexander Riedel
SAPIEN Technologies, Inc.