programming-examples/c-sharp/Games_&_Threads/C# Program to Create Thread Pools.cs

47 lines
1.1 KiB
C#
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*
* C# Program to Create Thread Pools
*/
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();
}
}
/*
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