0% found this document useful (0 votes)
32 views8 pages

04 Task Performance 1 - ARG - Reyes, Abraham

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views8 pages

04 Task Performance 1 - ARG - Reyes, Abraham

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Reyes, Abraham M.

CLICK RUN:
CODE :

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Runtime.InteropServices;
using System.Text;

using System.Threading;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace ThreadTP

public partial class Form1 : Form

[DllImport("kernel32.dll")]

private static extern bool AllocConsole();

Thread threadA;

Thread threadB;

Thread threadC;

Thread threadD;

static bool IsThread = false;

public Form1()

InitializeComponent();

class MyThreadClass

public static void thread1()


{

for (int i = 0; i < 3; i++)

Thread thread = Thread.CurrentThread;

Console.WriteLine("Name of Thread : " + thread.Name + " = " + i);

Thread.Sleep(500);

public static void thread2()

for (int i = 0; i < 6; i++)

Thread thread = Thread.CurrentThread;

Console.WriteLine("Name of Thread : " + thread.Name + " = " + i);

Thread.Sleep(1500);

public static void thread3()

for (int i = 0; i < 3; i++)

Thread thread = Thread.CurrentThread;

Console.WriteLine("Name of Thread : " + thread.Name + " = " + i);

Thread.Sleep(1500);
}

public static void thread4()

for (int i = 0; i < 6; i++)

Thread thread = Thread.CurrentThread;

Console.WriteLine("Name of Thread : " + thread.Name + " = " + i);

Thread.Sleep(1500);

if (i == 5)

IsThread = true;

private void Form1_Load(object sender, EventArgs e)

AllocConsole();

private void btnrun_Click(object sender, EventArgs e)

{
threadA = new Thread(MyThreadClass.thread1);

threadB = new Thread(MyThreadClass.thread2);

threadC = new Thread(MyThreadClass.thread3);

threadD = new Thread(MyThreadClass.thread4);

// Set thread names

threadA.Name = "Thread A";

threadB.Name = "Thread B";

threadC.Name = "Thread C";

threadD.Name = "Thread D";

// Set thread priorities

threadA.Priority = ThreadPriority.Highest;

threadB.Priority = ThreadPriority.Normal;

threadC.Priority = ThreadPriority.AboveNormal;

threadD.Priority = ThreadPriority.BelowNormal;

Console.WriteLine("-Start the Thread- ");

// Start threads

threadA.Start();

threadC.Start();

threadD.Start();

threadB.Start();

// Wait for threads to finish


threadA.Join();

threadC.Join();

threadB.Join();

threadD.Join();

Console.WriteLine("-End of Thread- ");

if (IsThread)

lblStartEnd.Text = " -End of Thread-";

You might also like