Guest User

Untitled

a guest
Oct 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. class Log {
  2. [string]$path
  3.  
  4. # Constructor
  5. Log ([string] $path) { $this.path = $path }
  6.  
  7. [void] info ([String] $message) {
  8. Write-Host $message
  9. $message | Add-Content -Path $this.path -EA Stop
  10. }
  11.  
  12. }
  13.  
  14. $block = {
  15. foreach ($y in 1..100) {
  16. ($using:log).info("Logging from RSJob. Test #$y")
  17. }
  18. }
  19.  
  20. Try {
  21. $log = [Log]::New("$PSScriptRoot\test.txt")
  22. foreach($x in 1..100) {
  23. $log.info("Logging from Main function. Test #$x")
  24. }
  25. Start-RSJob -Name "job1" -ScriptBlock $block
  26. While ($true) {
  27. start-sleep 1
  28. }
  29.  
  30. }
  31. Finally {
  32. Get-RSJob -Name "job1" | Remove-RSJob -Force
  33. }
Add Comment
Please, Sign In to add comment