[英]Killing A Process in C#
So I'm just trying to explore the intricacies of C# and I wanted to make a simple program that would just kill a process. 所以我只是试图探索C#的复杂性,我想制作一个简单的程序来杀死一个进程。 Yes I know, that is what Task Manager is for but this is supposed to be a learning experience, this is what I have so far.
是的,我知道,这就是任务管理器的用途,但这应该是一次学习经历,这是我到目前为止所做的。
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace endProcess
{
class Program
{
private Process GetaProcess(string processname)
{
Process[] aProc = Process.GetProcessesByName(processname);
if (aProc.Length > 0)
return aProc[0];
else return null;
}
string selectProcess = "";
static void Main(string[] args)
{
Console.WriteLine("What process do you want to kill?");
selectProcess = Console.ReadLine();
Process myprc = Call GetAProcess(selectProcess);
myprc.Kill();
Console.ReadLine();
}
}
}
The issue comes where I made the comment. 这个问题出现在我发表评论的地方。 It says there should be a semicolon after GetAProcess and I have no idea why.
它说GetAProcess之后应该有一个分号,我不明白为什么。 Any help would be much appreciated.
任何帮助将非常感激。
You don't say Call GetaProcess
you simply say GetaProcess
你不是说
Call GetaProcess
你只是说GetaProcess
The line should look like this : Process myprc = GetaProcess(selectProcess);
该行应如下所示:
Process myprc = GetaProcess(selectProcess);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.