Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Help to run a blinking text code in background

$
0
0

Hi All,

I found a code on internet ,working code of  a function to blink a text. I am using the function in my pwershell application . But I want the blinking code to run in background.

The function is 

$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

I am expecting output like

hello1 blink1

hello2 blink2

hello3 blink3

where blink1,blink2,blink3 all blink synchronously . I have PS ver 2.0 .

I tried few methods but did not help . Please help.

Thanks.

Spark.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>