Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "TaskManager" and then click OK
Step 2: Design your form as below
Your main form name: Form1

Your run new task name: frmRunTask

Step 3: Add code to handle your form as below
Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TaskManager
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Process[] proc;
//Get all process running
void GetAllProcess()
{
proc = Process.GetProcesses();
listBox.Items.Clear();
foreach (Process p in proc)
listBox.Items.Add(p.ProcessName);
}
private void Form1_Load(object sender, EventArgs e)
{
GetAllProcess();
}
private void btnEndTask_Click(object sender, EventArgs e)
{
try
{
//Kill process
proc[listBox.SelectedIndex].Kill();
GetAllProcess();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void runNewTaskToolStripMenuItem_Click(object sender, EventArgs e)
{
using(frmRunTask frm=new frmRunTask())
{
if (frm.ShowDialog() == DialogResult.OK)
GetAllProcess();
}
}
}
}
frmRunTask
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TaskManager
{
public partial class frmRunTask : Form
{
public frmRunTask()
{
InitializeComponent();
}
private void btnRun_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtOpen.Text))
{
try
{
//Start new process
Process proc = new Process();
proc.StartInfo.FileName = txtOpen.Text;
proc.Start();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
VIDEO TUTORIALS