Hi,
When I use Sapien products to generate an EXE file of the PowerShell script, the $Host.Runspace.ThreadOptions = "ReuseThread" stops working and it is reporting "The property 'ThreadOptions' cannot be found on this object. Verify that the property exists and can be set"
Is it because it is an EXE, or is there another reason ?
Thank you
ThreadOptions ReuseThread not working
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: ThreadOptions ReuseThread not working
The host does not support / implement the Runspace property. Why do you need to change the runspace's ThreadOption?
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: ThreadOptions ReuseThread not working
When the statement is made from a PS console it works fine, it is only when passed via the EXE file that it reports what I previously stated.
Looking for an explanation to explain that behavior.
You stated that the host does not support or implement runspace property. But it does in a PS console, why not through the same PS code enveloped in an EXE ?
Thank you.
Looking for an explanation to explain that behavior.
You stated that the host does not support or implement runspace property. But it does in a PS console, why not through the same PS code enveloped in an EXE ?
Thank you.
Re: ThreadOptions ReuseThread not working
The console itself is a PowerShell host as well, but when you run an executable, it is using a different host. Unfortunately, Microsoft's documentation is spare on the subject.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: ThreadOptions ReuseThread not working
Apparently this property is not exposed to third party hosts. It is internal to PowerShell.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: ThreadOptions ReuseThread not working
Also note the following about ThreadOptions.
$host.Runspace.ThreadOptions.value__ = [System.Management.Automation.Runspaces.PSThreadOptions]::UseNewThread
is the correct method for setting this.
As David notes - some host implantations may not have this. You likely need a WMF 3 or later Net Framework host and the apartment type selected (MTA/STA).
AlsoPS D:\scripts> $host.Runspace.ThreadOptions = 1
Exception setting "ThreadOptions": "The thread options can only be changed if the apartment state is multithreaded apartment (MTA), the current
options are UseNewThread or UseCurrentThread, and the new value is ReuseThread."
$host.Runspace.ThreadOptions.value__ = [System.Management.Automation.Runspaces.PSThreadOptions]::UseNewThread
is the correct method for setting this.
As David notes - some host implantations may not have this. You likely need a WMF 3 or later Net Framework host and the apartment type selected (MTA/STA).
Re: ThreadOptions ReuseThread not working
With the Sapien implementation this is the "$host" in use:
Name : PrimalScriptHostImplementation
Version : 3.0.0.0
InstanceId : 12d52fb0-3fc8-431c-8c72-7aba3be25b4f
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData :
DebuggerEnabled : True
IsRunspacePushed :
Runspace :