Click here to Skip to main content
Click here to Skip to main content

My TaskManager

, , 30 Aug 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
A task manager with additional functionality
Screenshot - task.jpg

Introduction

I know that on Code Project there are a lot of process managers programmed by brilliant programmers. But I need some more functionally in these process managers. Therefore I created my own task manager.

Background

Why I created this process manager, the reason is that sometimes we need to release our memory in just a short time. It takes time to select unnecessary processes from the Windows task managers and kill them one by one. While running some games or any other programs that require high RAM when you have shortage of RAM, this poses a problem. You'll want to use the RAM by only system processes and your favorite processes.

Point of Interest

You can create a list of programs and after opening the program MyTaskManager.exe, you will press the button "kill list processes." All of the process you add to the kill list will kill automatically. One thing I keep in mind with this program is that if there is some precious process, like system processes and maybe some other processes, you may not want to stop them at any cost. You must therefore add them to the except list. This process will never kill, although you add it in the kill list or attempt to kill it by mistake.

How It Works

It also reads the files Kill_List.xml and Except_List.xml. Keep the information while running the program. You can add a program to the kill list by right clicking on the process to add and then adding it to the list. The kill list is the list that the user will kill the processes with by clicking the button "kill list processes." The except list is the list of processes that you want to not kill at any cost, whether you add them to the kill list by accident or select for them for killing. It works like Task Manager, but I added some things that are following, through which you can get some extra work done.

Screenshot - Menue.jpg

After right clicking on the process, you can choose one of four operations for the selected process.

  1. You can open the folder containing the process.
  2. You can kill the selected process if it is not in the except list.
  3. You can add it to the except list.
  4. You can add it to the kill list.
Screenshot - Kill_button.jpgScreenshot - more_buttons.jpg

By clicking the kill list, it will kill all the processes that you've added to the kill list. View kill list and view except list to get data from the files Kill_List.xml and Except_List.xml and to view your processes in both categories. "New Task" just works like "Run" in the Windows menu.

Code Overview

In this program, I get all processes of the system through the function GetProcesses.

string[] Mem_Usage = new string[100];
string[] ProcessNames = new string[100];
process = Process.GetProcesses();
noOfProcess = 0;
int i = 0;
ListViewItem lvi = new ListViewItem();
foreach (Process pro in process)
{
    String pathx = "";
    try
    {
    //get path of the procees 
        pathx = pro.Modules[0].FileName;
    //remove unnecessory special characters 
        pathx = pathx.Replace("\\??\\", "");
    // add whole path into string array
        path[i] = pathx.ToString();
    }
    Catch (Win32Exception)
    {
        path[i] = "";
    }
    // get the name of the process
    ProcessNames[i] = pro.ProcessName;
    // get the amount of ram using process
    Mem_Usage[i] = Convert.ToString(pro.PagedMemorySize64);
    // add process names into list view item
    lvi = new ListViewItem(ProcessNames[i]);
    // add momory usage by the process in to list item item as sub //item
    lvi.SubItems.Add(Mem_Usage[i]);
    // add list view item in to list view
    AddListViewItemsTolv(lvi);
    i++;
    // count numbers of process
    noOfProcess++;
}

After getting processes, we use one function, ReadXmlFile, for both the Except_List.xml and Kill_List.xml files.

public void ReadXmlFile(string filename)
{
    try
    {
        // name of the file to read
        reader = new XmlTextReader(filename);//,new 
        // it should handl whit space during reading
        reader.WhitespaceHandling = System.Xml.WhitespaceHandling.None;
        // define the string Process in Kill list
        PInKill_List = new string[100];
        bool bEnableProcessNamesContent = false;
        bool bEnableProcessContent = false;
        int i = 0;
        // read upto end
        while (reader.Read())
        {
            // check the node of the reading data
            switch (reader.NodeType)
            {     
                //is it a Element of the node
                case System.Xml.XmlNodeType.Element:
                    bEnableProcessNamesContent = 
                       (reader.Name == "PorecessNames");
                    bEnableProcessContent = (reader.Name == "Process");
                    break;
                 // check for text in the node
                 case System.Xml.XmlNodeType.Text:
                     // add the value into text box
                     txtbox.Text += reader.Value + "\n";
                     PInKill_List[i] = reader.Value;
                     PInKill_List[i] = PInKill_List[i].TrimEnd('\r');
                     if (check)
                         noOfTageExist++;
                         i++;
                         break;
                }
            }
            check = false;
            reader.Close();
        } // end of try 
        catch (Exception)
        {
            reader.Close();
        }
    } 

}

I use the timer event to check processes after a specific time.

public System.Timers.Timer timer = new System.Timers.Timer(4000);

The default time is 4 seconds, but the user can change the time of the refresh rate from 1 second up to 8 seconds. After the timer event call, I call the function Check4Process, which will compare the number of old processes with the number of new process. If it is the same, then leave it. If not, then the GetProcesss function will call again and add it to the list view control.

private void Check4Processes()
{
    Process[] gPro = Process.GetProcesses();
    int Numpro = 0;
    string[] names = new string[100];
    string[] mem = new string[100];
    foreach (Process pro in gPro)
    {
        names[Numpro] = pro.ProcessName;
        mem[Numpro] = Convert.ToString(pro.PagedMemorySize64);
        Numpro++;
    }
    // if nuber of process are decrease 
    if (Numpro < noOfProcess)
    {
        //no of process are decreased
        GetProcesses();
        AddtoControl();
    }
    // if new process is added
    if (Numpro > noOfProcess)
    {
        // no of Process are increased
        GetProcesses();
        AddtoControl();
    }
}

In Kill_List, the function Check_Porcess_In_ExceptList is used when we are going to kill any process. We check whether it exists in the except list or not and return the bool value.

public bool Check_Process_in_ExceptList(string toCheck, Kill_List Except_Obj)
{
    //SelectedProcess
    //Kill_List Except_Obj = new Kill_List("Except_List");
    Except_Obj.ReadXmlFile("Kill List.xml");
    Except_Obj.Show();
    string pNames = Except_Obj.txtbox.Text;
    bool found =false;
    string[] SingleProcessName = ConvertStringToStringArray(pNames);
    foreach(string str in SingleProcessName)
    {
        //found = (toCheck == str ? true : false);
        //System.Windows.Forms.MessageBox.Show(str);
        if(toCheck ==str)
        {
            found = true;
            break;
        }
    }
    return found;
}

History

  • 30 August, 2007 -- Original version posted

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Authors

Naveed Khan

Pakistan Pakistan
No Biography provided

Naveed727
Software Developer
Pakistan Pakistan
I am working as Software Developer in www.Dynamologic.com.

Comments and Discussions

 
QuestionResult does not match that from the system task manager PinmemberLeoLiu_7-Jun-11 19:43 
GeneralMy vote of 1 Pinmemberkarim aslam5-Feb-11 22:45 
GeneralQuestion: Task manager "Except" list C# function to VB.net Pinmemberjlkdaslkfjd11-Sep-10 22:17 
Questionrun... [modified] Pinmembermoncayos5-May-09 15:04 
AnswerRe: run... PinmemberNaveed khan nido6-May-09 17:30 
Generaladvice Pinmembery_12345678_913-Sep-08 6:47 
GeneralMy Task Manager PinmemberShowMeHow20-Jun-08 9:09 
GeneralRe: My Task Manager PinmemberEliottA2-Feb-09 9:19 
Generala comment by Miszou PinadminSean Ewington4-Sep-07 3:36 
Questionhow to start demo Pinmemberdan o3-Sep-07 21:41 
AnswerRe: how to start demo Pinmembercdgwinn4-Sep-07 16:58 
GeneralRe: how to start demo Pinmemberdan o4-Sep-07 21:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 30 Aug 2007
Article Copyright 2007 by Naveed Khan, Naveed727
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid