Sunday 3 December 2017

C# Program to Create Thread Pools


Code:

using System;
using System.Threading;
class ThreadPoolDemo
{
    public void task1(object obj)
    {
        for (int i = 0; i <= 2; i++)
        {
            Console.WriteLine("Task 1 is being executed");
        }
    }
    public void task2(object obj)
    {
        for (int i = 0; i <= 2; i++)
        {
            Console.WriteLine("Task 2 is being executed");
        }
    }

    static void Main()
    {
        ThreadPoolDemo tpd = new ThreadPoolDemo();
        for (int i = 0; i < 2; i++)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(tpd.task1));
            ThreadPool.QueueUserWorkItem(new WaitCallback(tpd.task2));
        }

        Console.Read();
    }
}


Output:

Task 1 is being executed
Task 1 is being executed
Task 1 is being executed
Task 1 is being executed
Task 1 is being executed
Task 1 is being executed
Task 2 is being executed
Task 2 is being executed
Task 2 is being executed
Task 2 is being executed
Task 2 is being executed
Task 2 is being executed


More C# Programs:




















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...