可以从异常中获取进程ID吗?

Can get process ID from exception?

正在尝试使用 WebClient.DownloadFile 将更新部署到 .dll。如果 dll 被程序 loaded/locked 覆盖,那么我正在尝试使用 Try...Catch 语句(在以下异常中)来管理进程 ID 和它的 .Dispose() 。

System.Net.WebException: 'An exception occurred during a WebClient request.'

Inner Exception 
IOException: The process cannot access the file 'xyz' because it is being used by another process. 

这可能是也可能不是最好的方法...下面是我的代码。非常感谢任何指点!

        Try
            Using WC As New WebClient
                WC.DownloadFile("https://urlgoeshere.com/library.dll", strLiveDLL)
            End Using

        Catch ex1 As System.Net.WebException
            Using P As Process = ex1.WhatGoesHere 'can get the process ID here??
                If MsgBox("Cannot update because dll file is locked by " & P.ProcessName & vbCr &
                   "Press OK to dispose of this process and continue with update.",
                    MsgBoxStyle.OkCancel & MsgBoxStyle.Question,
                   "Update Interrupted") = MsgBoxResult.Ok Then
                    P.Dispose()
                    'continue with update
                Else
                    MsgBox("Update Aborted.")
                End If

            End Using
        Catch ex2 As IOException
            '
        Catch ex3 As Exception
            '
        End Try

如果其他人有兴趣,我从来没有弄清楚如何从异常中获取进程 ID(我认为这是不可能的)但我发现这可能没有必要...

我正在做的只是重命名 DLL(如果它被锁定)(即使在重命名之后,一切似乎仍然 运行 符合预期)。重命名后,可以将更新后的 DLL 下载到实时 DLL 的标准位置。