Cistoran
Cistoran

Reputation: 1597

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. 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. Any help would be much appreciated.

Upvotes: 2

Views: 1231

Answers (1)

Jesus Ramos
Jesus Ramos

Reputation: 23266

You don't say Call GetaProcess you simply say GetaProcess

The line should look like this : Process myprc = GetaProcess(selectProcess);

Upvotes: 9

Related Questions