I was hoping somebody out there could help me please, I have an application which uses threading, process and runs cmd.exe - the problem I have is that I cant cancel the command.
I have one textbox and two command buttonts, button 1 is run and button 2 is cancel - for this testing purpose only (my app wont be pinging but I'm doing this for testing only) I'm hoping to enter an I.P address in the textbox and then click on Run which starts a thread and the process, which so far is working. the coding I use to run the command is..
Dim myProcess As Process = New Process Dim s As String myProcess.StartInfo.FileName = "c:\windows\system32\cmd.exe" myProcess.StartInfo.UseShellExecute = False myProcess.StartInfo.CreateNoWindow = True myProcess.StartInfo.RedirectStandardInput = True myProcess.StartInfo.RedirectStandardOutput = True myProcess.StartInfo.RedirectStandardError = True myProcess.Start() Dim sIn As System.IO.StreamWriter = myProcess.StandardInput Dim sOut As System.IO.StreamReader = myProcess.StandardOutput Dim sErr As System.IO.StreamReader = myProcess.StandardError sIn.AutoFlush = True sIn.Write("ping " & TextBox1.Text & " >C:\pingtest.txt" & System.Environment.NewLine) sIn.Write("exit" & System.Environment.NewLine) s = sOut.ReadToEnd() If Not myProcess.HasExited Then myProcess.Kill() End If sIn.Close() sOut.Close() sErr.Close() myProcess.Close()
Now comes to difficult part, whilst the command is running I want to click on cancel which kills the thread and process which I have done but I have hit a brick wall because even though my thread and process has been killed my command carried on running, what I would like is the moment the cancel button is clicked to kill the thread, process and the command. I have tried everything underneath the sun but can't resolve this problem, can anyone help please?