Build Executable - Console Window doesn't automatcially close?

Issue #79 new
BrandonC created an issue

I am building an executable and everything runs perfectly, except I noticed the console window for the application doesn't close when I close out the GUI. I was hiding the console window at first but making it visible I can see that it does need to be manually closed right now in order for the exe to actually close.

Is there something I can set or run to make sure the console window closes when i close my application?

Thank you.

Visual Studio 2017 Name Value ---- ----- PSVersion 5.1.14393.2248 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.14393.2248 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Comments (3)

  1. Adam Driscoll

    Can you give me a little sample of the script you are packaging and how you are packaging the script (settings for Merge-Script)?

  2. BrandonC reporter
    #Initializing the runspaces
    $Global:syncHash = [hashtable]::Synchronized(@{})
    $newRunspace =[runspacefactory]::CreateRunspace()
    $newRunspace.ApartmentState = "STA"
    $newRunspace.ThreadOptions = "ReuseThread"
    $newRunspace.Open()
    $newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
    
    # Load WPF assembly if necessary
    [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
    
    
    
    $psCmd = [PowerShell]::Create().AddScript({})
    $psCmd.Runspace = $newRunspace
    $data = $psCmd.BeginInvoke()
    

    The meat of the code I'm packaging is inside $psCmd = [PowerShell]::Create().AddScript({})

    I'm packaging the script by selecting the entrypoint in the advanced properties of the project and building the solution. I"m not using merge-script at all to my knowledge

  3. Shawn Melton

    I can confirm I'm seeing the same behavior.

    [CmdletBinding()]
    param(
        [object[]]$Server,
        [int]$Port,
        [switch]$ConfigOnly
    )
    
    . "$PSScriptRoot\New-ReportAssessment.ps1"
    
    # Forcing a version to be used to make this more stable
    Import-Module dbatools -RequiredVersion 0.9.784 -Verbose:$false
    
    $fileDate = Get-Date -Format yyyyMMdd_HHmmss
    
    foreach ($s in $Server) {
        try {
            New-ReportAssessment -server $s -port $Port -configOnly:$ConfigOnly | Out-File "$server_assessment_$fileDate.html"
        } catch {
            "Error found exeucting command: $($_.Exception)"
        }
    }
    

    The dot sourced script is simply running Invoke-DbaQuery and collecting data to build out an HTML file. Even when the function New-ReportAssessment fails the console will remain open.

  4. Log in to comment