小编Pau*_*aul的帖子

完成后自动删除 PowerShell 作业(异步)

我有一个 PowerShell cmdlet,用于简化通过 RDP 连接到另一台计算机的过程。

在该 cmdlet 中,我运行执行以下操作:

    if ($null -ne $Username -and $null -ne $Password) {
        Start-Process -FilePath "cmdkey.exe" -ArgumentList @("/generic:`"TERMSRV/$ComputerName`"", "/user:`"$Username`"", "/pass:`"$Password`"") -WindowStyle Hidden
    }

    Start-Job -ScriptBlock {
        param($InstallPath, $ComputerName, $Port, $Username, $Password)

        $arguments = @("`"$(Join-Path $InstallPath '\Support Files\MSTSC\Default.rdp')`"")
        if ($null -ne $Port) {
            $arguments += "/v:`"$($ComputerName):$($Port)`""
        } else {
            $arguments += "/v:`"$($ComputerName)`""
        }

        Start-Process -FilePath "mstsc.exe" -ArgumentList $arguments -Wait

        if ($null -ne $Username -and $null -ne $Password) {
            Start-Process -FilePath "cmdkey.exe" -ArgumentList @("/delete:`"TERMSRV/$ComputerName`"") -WindowStyle Hidden
        }
    } …
Run Code Online (Sandbox Code Playgroud)

powershell jobs powershell-cmdlet

6
推荐指数
1
解决办法
9832
查看次数

WPF只能打开一个窗口吗?

假设在WinForms项目中有两个项目,一个WinForms项目和一个WPF项目,以下代码在Main()中并删除Application.Run没有问题:

        while (true)
        {
            Thread.Sleep(1000);
            Form1 window = new Form1();
            window.Show();
            Thread.Sleep(1000);
            window.Close();
        }
Run Code Online (Sandbox Code Playgroud)

但是,在WPF应用程序中,删除StartupUri ="Window1.xaml",然后创建:

    public App()
    {
        while (true)
        {
            Thread.Sleep(1000);
            Window window = new Window();
            window.Show();
            Thread.Sleep(1000);
            window.Close();
        }
    }
Run Code Online (Sandbox Code Playgroud)

程序无限循环,但Window只打开一次?

.net c# wpf

2
推荐指数
1
解决办法
9209
查看次数

标签 统计

.net ×1

c# ×1

jobs ×1

powershell ×1

powershell-cmdlet ×1

wpf ×1