sora90 0 Newbie Poster

I am trying to block a list of processes from Txt file/ Listbox Process using Timer. Here's a list of the codes

Code blocks are created by indenting at least 4 spaces
... and can span multiple lines


Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
    If appBox.Items IsNot Nothing Then
        Dim aBlock As StreamReader
        'Dim Proc2() As Process = Process.GetProcessesByName(appBox.SelectedItem)
        aBlock = New IO.StreamReader("C:\Users\Asus\Documents\Visual Studio 2010\Projects\FYP\FYP\Blocked.txt")
        Dim Proc2() As Process = Process.GetProcessesByName(aBlock.ReadLine)

        'While (aBlock.Peek() >= 0)

        For Each p As Process In Proc2         
            p.Kill()
            MessageBox.Show("Shouldn't you be working?")
        Next
        'End While

    End If
    gBlockList.Close()
End Sub

I can block processes from the list using SelectedItem, but it doesn't block all the process in the list. Using while loop causes a deadlock error here. I'm now using aBlock.ReadLine to read from txt file and block the available process. However it is only able to block the first process. Need some guidance on how this code can be used to block all the processes in the list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.