我有一个 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) 假设在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只打开一次?