locked
Error when working with WPK RRS feed

  • Question

  • I'm trying to show an ok button.  When running the folowing code in the ISE, it works fine:

    import-module powershellpack

    new-button "Hello" -show

    But in the Powershell console, I get the following strange message:

    PS C:\Scripts> new-button "Hello" -show
    New-Object : Exception calling ".ctor" with "0" argument(s): "The calling thread must be STA, because many UI component
    s require this."
    At C:\Users\Grant\Documents\WindowsPowerShell\Modules\WPK\GeneratedControls\PresentationFramework.ps1:12451 char:29
    +         $Object = New-Object <<<<  System.Windows.Controls.Button
        + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
        + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

     

    Does this mean that I can only use WPK in the ISE?


    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"
    Saturday, September 10, 2011 11:37 AM

Answers

  • New-Object : Exception calling ".ctor" with "0" argument(s): "The calling thread must be STA, because many UI components require this."
    At

    Start Powershell like this powershell -sta

    Certain aspects of visual styles require a single threaded apartment.

    The ISE is STA and it cannot be changed to MTA becuse it is hosted in a GUI the require STA.

     

     

     


    jv
    • Marked as answer by Bigteddy Saturday, September 10, 2011 1:12 PM
    Saturday, September 10, 2011 12:59 PM

All replies

  • New-Object : Exception calling ".ctor" with "0" argument(s): "The calling thread must be STA, because many UI components require this."
    At

    Start Powershell like this powershell -sta

    Certain aspects of visual styles require a single threaded apartment.

    The ISE is STA and it cannot be changed to MTA becuse it is hosted in a GUI the require STA.

     

     

     


    jv
    • Marked as answer by Bigteddy Saturday, September 10, 2011 1:12 PM
    Saturday, September 10, 2011 12:59 PM
  • Thank, jv.  That means I'm not wasting my time trying to figure out how to work with visual .net objects in PS. 

    I think it will help me to better understand these objects using a language that I'm familiar with.  In Visual C#, you don't have to worry about coding the design of a form, but I'd like to be able to code it from scratch.

     


    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"
    Saturday, September 10, 2011 1:12 PM
  • Thank, jv.  That means I'm not wasting my time trying to figure out how to work with visual .net objects in PS. 

    I think it will help me to better understand these objects using a language that I'm familiar with.  In Visual C#, you don't have to worry about coding the design of a form, but I'd like to be able to code it from scratch.

     


    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"


    Why do you say that?

    TO learn Windows FOrms and PowerSHell try using PrimalFormsCE.  It's free and has a GUI designer.

    Go here and download the trial.  It's a very good learning tool.

    http://sapien.com/software/primalforms#

     


    jv
    Saturday, September 10, 2011 1:30 PM