小编Car*_*001的帖子

Powershell 中的 Runspace Dispose(特定于 GUI)

我是 StackOverflow 的活跃读者,因为它通常可以帮助我解决所有问题。
但是对于我的第一个问题,我会就 Powershell 中的运行空间(特别是内存管理)向您寻求帮助。

我创建了一些带有 GUI 的 PS 应用程序,现在我使用运行空间来避免在运行大型操作时挂起 GUI。我的问题是我无法在运行空间完成后处理它们。

关于下面的代码,这是一个简单的脚本,试图了解我如何处理我的运行空间。我试图合并一个独特的运行空间来监视和处理应用程序运行空间,我从proxb 的脚本(顺便说一句,巨大的粉丝)中启发了自己,但它似乎不起作用。

每次我执行运行空间时,我都会获得 10Mb 的内存,巨大的泄漏!

泄露

你能帮我解决这个问题吗?

[xml]$xaml = @'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Runspace" FontFamily="Calibri" Height="400" Width="400" FontSize="14">
    <Grid Margin="10,10,10,10">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="10"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TextBox x:Name="TB_Results" Grid.Row="0" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"/>
        <Button x:Name="BT_Run" Grid.Row="2" Content="Run" Height="30"/>
    </Grid>
</Window>
'@

# Inits
Add-Type -AssemblyName PresentationFramework            
Add-Type -AssemblyName PresentationCore
Add-Type -AssemblyName WindowsBase
$gui = [hashtable]::Synchronized(@{})
$reader = (New-Object Xml.XmlNodeReader $xaml)
$gui.Window = [Windows.Markup.XamlReader]::Load($reader)
$xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object { $gui.Add($_.Name,$gui.Window.FindName($_.Name)) …
Run Code Online (Sandbox Code Playgroud)

powershell dispose runspace

5
推荐指数
1
解决办法
2301
查看次数

标签 统计

dispose ×1

powershell ×1

runspace ×1