Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在新线程powershell中调用函数_Powershell_Powershell 2.0 - Fatal编程技术网

在新线程powershell中调用函数

在新线程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 2)。
我怎样才能在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事件来执行此操作,它在事件发生时运行操作。这只是意味着你不需要担心其他线程/作业等