Multithreading 
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
 
Using System.Threading;
 
namespace student
{
<summary>
Summary description of the Form1.
</summary>
public class Form1:System.Windows.Forms.Form
{
Private System.Windows.Forms.Button button1;
Private System.Windows.Forms.Button button2;
Private System.Windows.Forms.Button Button3;
 
ArrayList threads = new ArrayList ();
 
Private System.Windows.Forms.ListView ListView1;
Private System.Windows.Forms.ColumnHeader ColumnHeader1;
Private System.Windows.Forms.ColumnHeader ColumnHeader2;
<summary>
The required designer variable.
</summary>
Private System.ComponentModel.Container components = null;
 
Public Form1 ()
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();
 
//
TODO: Add any constructor code after the InitializeComponent call
//
}
 
<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}
 
Code generated #region the Windows forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This.button1 = new System.Windows.Forms.Button ();
This.button2 = new System.Windows.Forms.Button ();
This.button3 = new System.Windows.Forms.Button ();
This.listview1 = new System.Windows.Forms.ListView ();
This.columnheader1 = new System.Windows.Forms.ColumnHeader ();
This.columnheader2 = new System.Windows.Forms.ColumnHeader ();
This. SuspendLayout ();
//
Button1
//
This.button1.Location = new System.Drawing.Point (24, 216);
This.button1.Name = "Button1";
This.button1.TabIndex = 1;
This.button1.Text = "ADD";
This.button1.Click + = new System.EventHandler (This.button1_click);
//
Button2
//
This.button2.Location = new System.Drawing.Point (104, 216);
This.button2.Name = "Button2";
This.button2.TabIndex = 2;
This.button2.Text = "Del";
This.button2.Click + = new System.EventHandler (This.button2_click);
//
Button3
//
This.button3.Location = new System.Drawing.Point (184, 216);
This.button3.Name = "Button3";
This.button3.TabIndex = 3;
This.button3.Text = "Delall";
This.button3.Click + = new System.EventHandler (This.button3_click);
//
ListView1
//
This.listView1.Columns.AddRange (new system.windows.forms.columnheader[] {
This.columnheader1,
This.columnheader2});
This.listView1.FullRowSelect = true;
This.listView1.GridLines = true;
This.listView1.Location = new System.Drawing.Point (0, 0);
This.listView1.Name = "ListView1";
This.listView1.Size = new System.Drawing.Size (288, 208);
This.listView1.TabIndex = 5;
This.listView1.View = System.Windows.Forms.View.Details;
//
ColumnHeader1
//
This.columnHeader1.Text = "thread number";
This.columnHeader1.Width = 81;
//
ColumnHeader2
//
This.columnHeader2.Text = "value";
This.columnHeader2.Width = 180;
//
Form1
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (292, 266);
This. Controls.Add (THIS.LISTVIEW1);
This. Controls.Add (This.button3);
This. Controls.Add (This.button2);
This. Controls.Add (This.button1);
This. Name = "Form1";
This. Text = "Form1";
This. Load + = new System.EventHandler (this. Form1_Load);
This. ResumeLayout (FALSE);
 
}
#endregion
 
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.Run (New Form1 ());
}
 
private void Form1_Load (object sender, System.EventArgs e)
{
}
 
private void Button1_Click (object sender, System.EventArgs e)
{
ADD ();
}
 
private void Button2_Click (object sender, System.EventArgs e)
{
Del ();
}
 
private void Button3_Click (object sender, System.EventArgs e)
{
 
    while (Threads. count>0) 
    {
     thread t1 = (Thread) threads[0]; 
     if (t1. IsAlive) 
     {
      t1. Abort (); 
     } 
     threads. RemoveAt (0); 
     lock (listView1) 
     {
       ListView1.Items.RemoveAt (0); 
     } 
    } 
   } 
 
   private void Add () 
   {
    int count = threads. Count; 
    if (count<10) 
    {
     thread t = new Thread (new ThreadStart (Process)); 
     t.start (); 
     threads. ADD (t); 
     lock (listView1) 
     {
       ListView1.Items.Insert (count, New ListViewItem (new String[]{count). ToString (), "0"})); 
     } 
    } 
   } 
 
   private void Del () 
   {
    int count = threads. Count; 
    if (count>0) 
    {
     thread t1 = (Thread) THREADS[COUNT-1]; 
     if (t1. IsAlive) 
     {
      t1. Abort (); 
     } 
     threads. RemoveAt (count-1); 
     lock (listView1) 
     {
       ListView1.Items.RemoveAt (count-1); 
     } 
    } 
   } 
 
private void Process ()
{
int i = 1;
while (true)
{
i++;
Int j = Threads. IndexOf (Thread.CurrentThread);
Lock (ListView1)
{
LISTVIEW1.ITEMS[J]. SUBITEMS[1]. Text = i.ToString ();
}
Thread.Sleep (0);
}
}
}
}