Closed KirkMunro closed 6 years ago
I don't quite understand the need for sleep/delay in thread jobs. There is already a ThrottleLimit parameter and queue to delay jobs from starting all at once and limit the number of jobs running concurrently. But if you want a way to start a thread job based on the completion of another thread job, then that becomes more difficult. I created thread jobs to be as similar as possible to generic PowerShell jobs, and that job infrastructure doesn't really support that kind of async/await threading. Also PowerShell threading is based on Runspaces, which have isolation that makes sharing data more difficult.
I would like to see threading semantics added to PowerShell language, and I think some proposals have been made on github. But ThreadJobs are really just PowerShell jobs that run in their own thread/runspace.
You're right, I did some testing, and I don't need sleep/delay in the thread jobs. ThreadJob already handles what I need.
Hi @PaulHigin,
This module seems to be close to what I was looking for...a way to run a PowerShell script block in a multi-threaded fashion. In my case, I already have one runspace per thread, and I run the script blocks in the runspaces. What I don't have, that I would like to have, is the PS equivalent of async/await, so that threads can properly run simultaneously. I was thinking about using the script block AST and injecting [system.threading.thread]::Sleep invocations with very short delays (100ms) into the script block before it is run, but that doesn't help for commands that are run across a network and may take a while. Do you have any thoughts on how someone could use this module to run multiple script blocks in different runspaces in a multi-threaded fashion without having to add Start-Sleep or [system.threading.thread]::Sleep invocations into the script?
Kirk