【问题标题】:Method invocation failed because [System.RuntimeType] for GetCurrentThreadId方法调用失败,因为 GetCurrentThreadId 的 [System.RuntimeType]
【发布时间】:2023-02-09 20:58:42
【问题描述】:

我想用下面的 powershell 脚本获取 Windows 进程的内存转储。

我曾经尝试过这个脚本。但它给出以下错误:

方法调用失败,因为 [System.RuntimeType] 不包含 名为“GetCurrentThreadId”的方法。

#############################################################
$process = Get-Process -Name AggregatorHost
$threadId = [System.Diagnostics.Process].GetCurrentThreadId()
$thread = $process.Threads | Where-Object { $_.Id -eq $threadId }
$thread.Export("test.dmp")
###################################################################

如何解决这个问题或者如果你有其他方法请告诉我?

powershell内存转储

【问题讨论】:

    标签: windows powershell


    【解决方案1】:

    Process.GetCurrentTheadId 是一个静止的方法,因此您需要使用静态成员调用运算符::(相对于常规成员调用运算符.):

    [System.Diagnostics.Process]::GetCurrentThreadId()
    

    话虽这么说,我怀疑您提供的代码是否会按照您的预期进行 - GetCurrentThreadId 将从执行线程中获取线程 ID在powershell进程中,并且您不会找到相同的线程 ID属于另一个进程在同一个引导周期

    【讨论】:

      猜你喜欢
      • 2018-11-27
      • 2013-07-03
      • 2020-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多