当前位置: 首页>>代码示例>>C#>>正文


C# Process.Kill方法代码示例

本文整理汇总了C#中System.Diagnostics.Process.Kill方法的典型用法代码示例。如果您正苦于以下问题:C# Process.Kill方法的具体用法?C# Process.Kill怎么用?C# Process.Kill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.Process的用法示例。


在下文中一共展示了Process.Kill方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetThumbnailFromProcess

        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;
            }
              }
            }
              }
        }
开发者ID:renanxr3,项目名称:simpleDLNA,代码行数:35,代码来源:VideoThumbnails.cs

示例2: beginInArcadeMode

        private void beginInArcadeMode(ref GameConfiguration gameConfig)
        {
            Boolean closed = true;
            Boolean stopRunner = false;
            Process game = new Process();
            Process joyToKey = new Process();
            GlobalMouseKeyboard globalMouseKeyboard = new GlobalMouseKeyboard();

            runJoyToKey(ref gameConfig);

            while (!stopRunner)
            {
                if (globalMouseKeyboard.F2IsPressed)
                {
                    //restart the game
                    game.Kill();
                    closed = true;
                    globalMouseKeyboard.F2IsPressed = false;
                }

                if (globalMouseKeyboard.F4IsPressed)
                {
                    //end arcade mode
                    game.Kill();
                    stopRunner = true;
                    globalMouseKeyboard.Dispose();
                }

                if (closed)
                {
                    if (gameConfig.HideMouse)
                        Cursor.Position = new Point(2000, 2000); //work around
                        //another work around, set the cursor graphic to a transparent one, http://forums.whirlpool.net.au/archive/1172326

                    ProcessStartInfo psi = new ProcessStartInfo(gameConfig.GamePath);
                    if (gameConfig.FullScreen)
                        psi.WindowStyle = ProcessWindowStyle.Maximized; //TODO: only maximizes fully if the taskbar is set to auto-hide
                    game = Process.Start(psi);

                    closed = false;
                }

                game.WaitForExit(100); //? to reduce cpu usage?

                if (game.HasExited)
                {
                    closed = true;
                }
            }
        }
开发者ID:edibletoaster,项目名称:Babycastles-Trollkit,代码行数:50,代码来源:GameHandler.cs

示例3: t_Elapsed

        public void t_Elapsed(object sender, ElapsedEventArgs e, Process p, string date)
        {
            Timer t = (Timer)sender;
            t.Stop();

            if (p.ProcessName == "java")
            {
                if (Utilities.scanProcess(p))
                {
                    if (AntiPwny.PreventionMode)
                    {
                        builder.Clear();
                        builder.Append(p.ProcessName);
                        builder.Append(" Killed.");
                        p.Kill();

                        w.write(date, builder.ToString(), "Java Meterpreter");
                    }
                    else
                    {
                        builder.Clear();
                        builder.Append(p.ProcessName);
                        builder.Append(" memory contains java meterpreter signature.");

                        w.write(date, builder.ToString(), "Java Meterpreter Found");
                    }
                }
            }
            if (Utilities.scanProcess(p))
            {
                if (AntiPwny.PreventionMode)
                {
                    builder.Clear();
                    builder.Append(p.ProcessName);
                    builder.Append(" Killed.");
                    p.Kill();

                    w.write(date, builder.ToString(), "Meterpreter");
                }
                else
                {
                    builder.Clear();
                    builder.Append(p.ProcessName);
                    builder.Append(" memory contains meterpreter signature.");

                    w.write(date, builder.ToString(), "Meterpreter Found");
                }
            }
        }
开发者ID:rvazarkar,项目名称:antipwny,代码行数:49,代码来源:ProcWatchers.cs

示例4: CreateGameProcess

        private void CreateGameProcess(int index, string strScript)
        {
            Process proc = new Process();
            proc.StartInfo.FileName = strScript;
            proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(strScript);
            //proc.StartInfo.CreateNoWindow = false;
            proc.StartInfo.UseShellExecute = false; 
            //proc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
            proc.Start();
            Thread.Sleep(500);

            //尝试5次捕捉MainWindowHandle
            for (int i = 0; i < 5; i++)
            {
                if (proc.MainWindowHandle == IntPtr.Zero)
                {
                    proc.Kill();
                    proc.Start();
                    Thread.Sleep(500);
                }
            }


            m_aProc[index] = proc;
            Debug.Print("MainWindowHandle:" + proc.MainWindowHandle.ToString());
            ResetAllWindow();
            proc.WaitForExit();
            m_aProc[index] = null;
        }
开发者ID:viticm,项目名称:pap2,代码行数:29,代码来源:FrmMain.cs

示例5: TestKill

 public void TestKill()
 {
     var killer = new ProcKiller(500);
     killer.Names.Add("cmd");
     //killer.Names.Add("sleep");
     Process proc = new Process();
     proc.StartInfo.UseShellExecute = false;
     proc.StartInfo.FileName = "test\\do_w.bat";
     proc.StartInfo.RedirectStandardOutput = true;
     proc.StartInfo.RedirectStandardError = true;
     proc.StartInfo.CreateNoWindow = true;
     proc.Start();
        // killer.Running.Add(proc.Id);
     String data;
     TaskPool.Queue(i =>
     {
         Exec.exec(out data, "test\\do_w.bat");
     }, 0);
     TaskPool.Queue(i =>
     {
         Exec.exec(out data, "test\\do_w.bat");
     }, 1);
     while (true)
     {
         Thread.Sleep(500);
         var ps=Process.GetProcessesByName("cmd");
         if (ps.Length==1)
         {
             break;
         }
     }
     Assert.AreEqual(1, Process.GetProcessesByName("cmd").Length);
     proc.Kill();
     Assert.AreEqual(0, Process.GetProcessesByName("cmd").Length);
 }
开发者ID:Centny,项目名称:cswf,代码行数:35,代码来源:ProcKillerTest.cs

示例6: Main

    static void Main()
    {
      var ps = new Process
      {
        StartInfo = new ProcessStartInfo
        {
          UseShellExecute = false,
          CreateNoWindow = true,
          FileName = "IronScheme.WebServer.exe",
          RedirectStandardError = true
          
        }
      };

      if (ps.Start())
      {
        Thread.Sleep(1000);

        if (!ps.HasExited)
        {
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          Application.Run(new MainForm());

          ps.Kill();
        }
        else
        {
          MessageBox.Show(ps.StandardError.ReadToEnd(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
      }
    }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:32,代码来源:Program.cs

示例7: Clone

        public static GitCloneResult Clone(string uri, string dest, string branch = null, int timeLimit = 1000 * 60 * 20)
        {
            if (!System.IO.Directory.Exists(dest))
                System.IO.Directory.CreateDirectory(dest);
            Process p = new Process();

            var argument = $"clone {uri}";
            if (!string.IsNullOrEmpty(branch))
                argument = $"clone {uri} -b {branch}";

            p.StartInfo = new ProcessStartInfo
            {
                RedirectStandardError = true,
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true,
                FileName = "git",
                Arguments = argument,
                WorkingDirectory = dest
            };
            p.Start();
            if (!p.WaitForExit(timeLimit))
                p.Kill();
            var ret = new GitCloneResult
            {
                IsSucceeded = true,
                Output = p.StandardOutput.ReadToEnd(),
                Error = p.StandardError.ReadToEnd()
            };
            if (p.ExitCode != 0)
                ret.IsSucceeded = false;
            return ret;
        }
开发者ID:CodeComb,项目名称:Package,代码行数:33,代码来源:GitClone.cs

示例8: RunProcess

        private void RunProcess(CancellationToken cancellationToken, Process process)
        {
            if (!cancellationToken.IsCancellationRequested)
            {
                Log.Debug("Starting process...");
                if (process.Start())
                {
                    do
                    {
                        process.WaitForExit(DefaultProcessWaitTime);
                    } while (!cancellationToken.IsCancellationRequested && !process.HasExited);
                }
                else
                {
                    Log.Debug("Process failed to launch");
                }
            }

            if (!process.HasExited)
            {
                Log.Debug("Cancellation requested: killing process");
                process.Kill();
            }

            Log.Debug("Process closed");
        }
开发者ID:middas,项目名称:SrcdsServiceWrapper,代码行数:26,代码来源:SrcdsHandler.cs

示例9: performSync

 private static void performSync(bool showStartWars)
 {
     Process startStarwars = new Process ();
     if (showStartWars) {
         startStarwars.StartInfo.FileName = "/usr/bin/telnet";
         startStarwars.StartInfo.Arguments = "towel.blinkenlights.nl";
         startStarwars.StartInfo.CreateNoWindow = false;
         startStarwars.Start ();
     }
     Process syncRepo = new Process ();
     syncRepo.StartInfo.FileName = "env/bin/repo";
     syncRepo.StartInfo.WorkingDirectory = ChoosableSettings.getInstance ().getWorkingDirectory ();
     syncRepo.StartInfo.Arguments = "sync";
     syncRepo.Start ();
     ConsoleColor saved = Console.ForegroundColor;
     Console.ForegroundColor = ConsoleColor.Blue;
     Console.WriteLine ("-------------------------------------------");
     syncRepo.WaitForExit ();
     if (showStartWars && !startStarwars.HasExited) {
         startStarwars.Kill ();
     }
     Console.WriteLine ("-------------------------------------------");
     Console.ForegroundColor = saved;
     Console.WriteLine ("Yeah! Finished syncing! You're now ready to build android for your devices! Go on and get the best android hacker in the world. may the force be with you! :D");
     Console.WriteLine ("Don't forget: (c) Android is a trademark of Google Inc. Never tell anybody you've made it!");
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine ("AND OF COURSE! IF YOU DESTROY YOUR PHONE! OR IT DON'T START ANYMORE OR ANYTHING ELSE: YOU'RE RESPONSIVE FOR THAT! NOT ME OR ANYBODY! RIGHT? Right!");
     Console.ForegroundColor = saved;
     Console.WriteLine ("Press [enter] to accept and go back to mainmenu");
     Console.ReadLine ();
     MainMenu.show ();
 }
开发者ID:lotrofans,项目名称:aosp_studio,代码行数:32,代码来源:RepoSync.cs

示例10: Initialise

        public bool Initialise(string Filename)
        {
            if (!File.Exists(Filename))
            {
                return false;
            }

            Sub = new Process();
            Sub.StartInfo.FileName = Filename;
            Sub.StartInfo.RedirectStandardInput = true;
            Sub.StartInfo.RedirectStandardOutput = true;
            Sub.StartInfo.CreateNoWindow = true;
            Sub.StartInfo.UseShellExecute = false;

            Sub.StartInfo.Arguments = "OutputInfo";
            Sub.Start();
            Name = Read();
            Version = Read();
            Owner = Read();
            try
            {
                Sub.Kill();
                Sub.WaitForExit();
            }
            catch { }
            Sub.StartInfo.Arguments = string.Empty;

            return true;
        }
开发者ID:hnefatl,项目名称:Arena,代码行数:29,代码来源:Bot.cs

示例11: ExtractAsync

 static async Task ExtractAsync(string filename, string destination, Progress progress)
 {
     Directory.Delete(destination, true);
     Directory.CreateDirectory(destination);
     var workingDir = Paths.ExecutingDirPath;
     var args = $"x \"{filename}\" -o\"{destination}\" -y";
     var si = new ProcessStartInfo(@"tools\7z.exe", args)
     {
         WorkingDirectory = workingDir,
         RedirectStandardOutput = true,
         RedirectStandardError = true,
         RedirectStandardInput = true,
         UseShellExecute = false
     };
     using (var proc = new Process { StartInfo = si })
     {
         proc.Start();
         var exited = await proc.WaitForExitAsync(ExtractionTimeout);
         if (!exited)
         {
             proc.Kill();
             throw new TimeoutException($"Extraction of '{filename}' took longer than {ExtractionTimeout}, aborting");
         }
         if (proc.ExitCode != 0)
         {
             // TODO: better exception type
             throw new Exception(
                 $"Failed to extract archive '{filename}'. 7zip exit code: {proc.ExitCode}\n{proc.StandardOutput.ReadToEnd()}\n{proc.StandardError.ReadToEnd()}");
         }
         progress?.CompletedInstall();
     }
 }
开发者ID:mattolenik,项目名称:winston,代码行数:32,代码来源:ArchiveExtractor.cs

示例12: Compile

        private void Compile(string project, string version)
        {
            string msbuild;
            using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0"))
            {
                var root = key.GetValue("MSBuildToolsPath") as string;
                msbuild = Path.Combine(root, "MSBuild.exe");
            }

            FileInfo fi = new FileInfo(project);
            var outPath = Path.GetTempPath();

            var p = new Process();
            p.StartInfo.FileName = msbuild;
            p.StartInfo.Arguments = string.Format(@" {0} /p:Configuration=Debug /t:Build /fileLogger /flp1:logfile=errors.txt;errorsonly  /p:SolutionDir={1} /p:SolutionName=PowerShellEditorServices /p:DefineConstants=PowerShellv{2} /p:OutDir={3}", project, fi.Directory.Parent.Parent.FullName, version, outPath);
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            p.WaitForExit(60000);
            if (!p.HasExited)
            {
                p.Kill();
                throw new Exception("Compilation didn't complete in 60 seconds.");
            }

            if (p.ExitCode != 0)
            {
                var errors = File.ReadAllText("errors.txt");
                throw new Exception(errors);
            }
        }
开发者ID:modulexcite,项目名称:PowerShellEditorServices,代码行数:31,代码来源:PowerShellVersionTests.cs

示例13: GetProcessOutputFirstLine

        private static string GetProcessOutputFirstLine(string filename, string arguments)
        {
            //Log.LogWarning(filename);
            var process = new Process
            {
                StartInfo = new ProcessStartInfo(filename, arguments)
                {
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true
                }
            };

            const int processWaitTime = 1000;
            string result = null;

            // we should get output asynchronous to avoid freezing
            process.OutputDataReceived += (sendingProcess, outLine) =>
            {
                if (result == null)   // get first line only
                {
                    result = outLine.Data;
                }
            };

            process.Start();
            process.BeginOutputReadLine();
            process.WaitForExit(processWaitTime);
            if (!process.HasExited)
            {
                process.Kill();
            }

            return result;
        }
开发者ID:VictorHaydin,项目名称:hgwcrev,代码行数:35,代码来源:Program.cs

示例14: TreeApplication

        public TreeApplication(string fileName)
        {
            this.processName = fileName;// +".exe";

            p = GetProcess(processName);
            if (p != null)
            {
                p.Kill();
            }

            ProcessStartInfo ps = new ProcessStartInfo { FileName = fileName };
            p = new Process();
            p.StartInfo = ps;
            p.Start();

            while (!p.Responding)
            {
                Trace.WriteLine("waiting process");
                Thread.Sleep(200);
            }

            while (app == null)
            {
                app = InitializeAutomationElement();
                Trace.WriteLine("waiting for app");
                Thread.Sleep(200);
            }
        }
开发者ID:CADblokeWPFforks,项目名称:MultiSelectTreeView,代码行数:28,代码来源:TreeApplication.cs

示例15: LineAssert

 static void LineAssert(string line, string readLine, Process process)
 {
     if (line != readLine) {
         process.Kill();
         Assert.Fail("Expected \"{0}\", found \"{1}\".", line, readLine);
     }
 }
开发者ID:pomma89,项目名称:DanglingLang,代码行数:7,代码来源:TestBase.cs


注:本文中的System.Diagnostics.Process.Kill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。