vb.net .vb 帮助,进程 p.Close() 问题

Jiale Xue - MSFT 41,426 信誉分 Microsoft 供应商
2024-03-14T07:42:03.03+00:00

你好 & 谢谢 ; WIn 10 与 2019

p.Close() not working for me .    
        Private Sub CloseIExplore()  
            Dim processArray As Process() = Process.GetProcessesByName("iexplore")  
            For Each p As Process In processArray  
                p.Close()  
                TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "For Each p As Process"  
            Next  
            TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "Private Sub CloseIExplore()"  
        End Sub  

它似乎运行良好,但它没有“结束任务”。 拜托,我做错了什么? 还有别的办法吗? 感谢您的帮助... 这是完整的程序代码。

' MouseUp Code from Daniel Zhang-MSFT   
' https://learn.microsoft.com/en-us/answers/questions/93390/vs-2019-vbnet-vb-how-to-capture-a-mouseup-event-in.html?childToView=94498#answer-94498   
Public Class Form1  
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
        '        WebBrowser1.DocumentText =  
        '    "<html><body>Please enter your name:<br/>" &  
        '    "<input type='text' name='userName'/><br/>" &  
        '    "<a href='http://www.microsoft.com'>continue</a>" &  
        '    "</body></html>"  
        WebBrowser1.ScriptErrorsSuppressed = True  
        WebBrowser1.IsWebBrowserContextMenuEnabled = False  
        '        Me.MinimumSize = New Size(1000, 650)  
        Me.StartPosition = FormStartPosition.CenterScreen  
        Me.Left = 40  
        Me.Top = 20  
        WebBrowser1.Navigate("https://www.kidzsearch.com/")  
    End Sub  

  
    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted  
        AddHandler WebBrowser1.Document.MouseUp, AddressOf eventSub  
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "Private Sub WebBrowser1_DocumentCompleted"  
    End Sub  
    Sub eventSub(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs)  
        Dim event_html As New HtmlElementEventHandler(AddressOf webMouseUp)  
        event_html.Invoke(sender, e)  
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "Sub eventSub"  
    End Sub  
    Sub webMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs)  
        If e.MouseButtonsPressed = Windows.Forms.MouseButtons.Left Then  
            '            MsgBox("left clicked!")  
        End If  
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "Sub webMouseUp"  
        CloseIExplore()  
    End Sub  
    Private Sub WebBrowser1_Navigating(sender As Object, e As WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating  
        '        If e.Url.ToString.Contains("about:blank") Or e.Url.ToString.Contains("xbox.com") Then  
        '            e.Cancel = True  
        '            End If  
        MsgBox("WebBrowser1_Navigating-To  " & e.Url.ToString)  
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & e.Url.ToString  

  
    End Sub  
    Private Sub CloseIExplore()  
        Dim processArray As Process() = Process.GetProcessesByName("iexplore")  
        For Each p As Process In processArray  
            p.Close()  
            TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "For Each p As Process"  
        Next  
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "Private Sub CloseIExplore()"  
    End Sub  

  
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
        WebBrowser1.GoBack()  
    End Sub  

  
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click  
        CloseIExplore()  
    End Sub  

  
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click  
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "----"  
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "----"  
    End Sub  
End Class  

Note:此问题总结整理于:vb.net .vb Help, trouble with Process p.Close()

Windows 窗体
Windows 窗体
一组用于开发图形用户界面的 .NET Framework 托管库。
167 个问题
VB
VB
Microsoft 开发的一种面向对象的编程语言,其在 .NET Framework 上实现。 以前称为 Visual Basic .NET。
86 个问题
0 个注释 无注释
{count} 票

接受的答案
  1. Hui Liu-MSFT 46,961 信誉分 Microsoft 供应商
    2024-03-14T09:29:38.22+00:00

    在您的另一个线程中,我已经详细解释了Process.Close()方法用于释放与此组件关联的所有资源。 您可以使用 Process.Kill() 或 Process.CloseMainWindow() 方法来停止关联的进程。 这个解决方案对你有用吗?如果没有,你遇到了什么问题?如果已解决,请点击“接受答案”。 对于同样的问题,我们建议在线程上进行讨论,而不是创建一个新线程。 感谢您的理解

    如果回复有帮助,请单击“接受答案”并投赞成票。

    注意:如果您想接收此线程的相关电子邮件通知,请按照我们文档中的步骤启用电子邮件通知。

    1 个人认为此答案很有帮助。
    0 个注释 无注释

0 个其他答案

排序依据: 非常有帮助