我在互联网上找到了一个代码,一个闪烁文本的函数的工作代码。我在我的 pwershell 应用程序中使用该函数。但我希望闪烁的代码在后台运行。功能是
$function = {
function Blink-Message {
param([String]$Message,[int]$Delay,[int]$Count,[ConsoleColor[]]$Colors)
$startColor = [Console]::ForegroundColor
$startLeft = [Console]::CursorLeft
$startTop = [Console]::CursorTop
$colorCount = $Colors.Length
$line = "$message"
for($i = 0; $i -lt $Count; $i++) {
[Console]::CursorLeft = $startLeft
[Console]::CursorTop = $startTop
[Console]::ForegroundColor = $Colors[$($i % $colorCount)]
[Console]::WriteLine($Message)
Start-Sleep -Milliseconds $Delay
}
[Console]::ForegroundColor = $startColor
}
}
# Set-Alias blink Blink-Message
#write-host -NoNewline "hello "; Blink-Message "blink" 1000 15 "red,black" | Receive-Job
write-host -NoNewline "hello1 "; start-job -InitializationScript $function -ScriptBlock {Blink-Message} -InputObject "blink1",1000,15,"red,black" | Receive-Job
write-host -NoNewline "hello2 "; start-job -InitializationScript $function -ScriptBlock {Blink-Message} -InputObject "blink2",1000,15,"red,black" | Receive-Job
write-host -NoNewline "hello3 "; start-job -InitializationScript $function -ScriptBlock {Blink-Message} -InputObject "blink3",1000,15,"red,black" | Receive-Job
任何建议表示赞赏。
谢谢。