在新线程powershell中调用函数
如何创建新线程并以异步方式运行?我有一个事件,它应该在运行时更新文本框,所以我需要在不同的线程中运行它。 (powershell 2)。在新线程powershell中调用函数,powershell,powershell-2.0,Powershell,Powershell 2.0,如何创建新线程并以异步方式运行?我有一个事件,它应该在运行时更新文本框,所以我需要在不同的线程中运行它。 (powershell 2)。 我怎样才能在PowerShell中做到这一点 你要找的是背景工作 以下是“帮助”中的几个示例: 使用“开始作业”启动作业: C:\PS>start-job -scriptblock {get-process} Id Name State HasMoreData Location Command --- ---- -----
我怎样才能在PowerShell中做到这一点 你要找的是背景工作 以下是“帮助”中的几个示例: 使用“开始作业”启动作业:
C:\PS>start-job -scriptblock {get-process}
Id Name State HasMoreData Location Command
--- ---- ----- ----------- -------- -------
1 Job1 Running True localhost get-process
使用AsJob参数启动作业:
C:\PS>$jobWRM = invoke-command -computerName (get-content servers.txt) -scriptblock {get-service winrm} -jobname WinRM -throttlelimit 16 -AsJob
如果您提供了一个小代码示例,我可以在我的答案中添加一些示例代码。您也可以使用Powershell事件来执行此操作,它在事件发生时运行操作。这只是意味着你不需要担心其他线程/作业等