-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
q.ps1
25 lines (21 loc) · 858 Bytes
/
q.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Import-Module "C:\projects\WPwshF\ObservableConcurrentQueue.dll"
$queue = [System.Collections.Concurrent.ObservableConcurrentQueue[object]]::new()
$e = Register-ObjectEvent -InputObject $queue -EventName ContentChanged -Action { Write-Host "new content" }
$psCmd = [powershell]::Create()
$syncHash = [hashtable]::Synchronized(@{})
$newRunspace =[runspacefactory]::CreateRunspace()
$newRunspace.Open()
$newRunspace.SessionStateProxy.SetVariable("queue",$queue)
$psCmd.Runspace = $newRunspace
$psCmd.AddScript({
$counter = 0
While ($true) {
$o = { Write-Host }
Start-Sleep -Seconds 1
"$(Get-Date) Adding $()" | Out-File -FilePath "c:\temp\put.txt" -Append
$queue.Enqueue(++$c)
"$(Get-Date) Added" | Out-File -FilePath "c:\temp\put.txt" -Append
}
})
$data = $psCmd.BeginInvoke()
# $psCmd.Stop()