I'm trying to create a small productivity program to keep myself focused when programming; specifically, to close any processes that might distract me from doing my job. I'm writing it in VB.NET for simplicity.
What is the easiest way to kill all processes listed in a listBox? I already know how to add the processes to my listBox with this code:
Dim newProc As New OpenFileDialog
'// Settings for the open file dialog. (I like how I use ' to start the comment, but // so I recognize it! :)
newProc.Filter = "Executable files (*.exe)|*.exe"
newProc.FileName = "..choose a file.."
newProc.Multiselect = True
newProc.CheckFileExists = True
newProc.CheckPathExists = True
newProc.AutoUpgradeEnabled = True
newProc.AddExtension = True
If (newProc.ShowDialog = Windows.Forms.Dialog开发者_运维百科Result.OK) Then
ListBox1.Items.AddRange(newProc.SafeFileNames)
End If
This adds the processes to the listBox very neatly and all, exactly how I want it. I have a timer that gets enabled with the press of a button that should close all processes in the listBox, but I'm unsure what I should use. Can I get some help? :(
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")
For Each p As Process In pProcess
p.Kill()
Next
You can try the above. Please view this link for further infomation.
精彩评论