System.Diagnostics.Process.Kill C# (CSharp) Method

Kill() public method

Stops the associated process immediately.
public Kill ( ) : void
return void
        public void Kill()
        {
            SafeProcessHandle handle = null;
            try
            {
                handle = GetProcessHandle(Interop.Advapi32.ProcessOptions.PROCESS_TERMINATE);
                if (!Interop.Kernel32.TerminateProcess(handle, -1))
                    throw new Win32Exception();
            }
            finally
            {
                ReleaseProcessHandle(handle);
            }
        }

Usage Example

Esempio n. 1
1
        private MemoryStream GetThumbnailFromProcess(Process p, ref int width, ref int height)
        {
            Debug("Starting ffmpeg");
              using (var thumb = new MemoryStream()) {
            var pump = new StreamPump(p.StandardOutput.BaseStream, thumb, null, 4096);
            if (!p.WaitForExit(20000)) {
              p.Kill();
              throw new ArgumentException("ffmpeg timed out");
            }
            if (p.ExitCode != 0) {
              throw new ArgumentException("ffmpeg does not understand the stream");
            }
            Debug("Done ffmpeg");
            if (!pump.Wait(2000)) {
              throw new ArgumentException("stream reading timed out");
            }
            if (thumb.Length == 0) {
              throw new ArgumentException("ffmpeg did not produce a result");
            }

            using (var img = Image.FromStream(thumb)) {
              using (var scaled = ThumbnailMaker.ResizeImage(img, ref width, ref height)) {
            var rv = new MemoryStream();
            try {
              scaled.Save(rv, ImageFormat.Jpeg);
              return rv;
            }
            catch (Exception) {
              rv.Dispose();
              throw;
            }
              }
            }
              }
        }
All Usage Examples Of System.Diagnostics.Process::Kill