Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
This blog shows on how to use a thread pooling with a code
WhatsApp
Karthikeyan Anbarasan
13y
2.7
k
0
0
25
Blog
This sample blog will show how to use thread pooling using C#
using System;
using
System
.Threading;
namespace Demo
{
class Program
{
static void Main()
{
int nWorkerThreads;
int nCompletionPortThreads;
ThreadPool.GetMaxThreads(out nWorkerThreads, out nCompletionPortThreads);
Console.WriteLine("Max worker threads: {0}, I/O completion threads: {1}", nWorkerThreads, nCompletionPortThreads);
for (int i = 0; i < 5; i++)
{
ThreadPool.QueueUserWorkItem(ThreadFuntion);
}
Thread.Sleep(3000);
}
static void ThreadFuntion(object state)
{
for (int i = 0; i < 3; i++)
{
Console.WriteLine("loop {0}, running inside pooled thread {1}", i,
Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(50);
}
}
}
}
This blog shows on how to use a thread pooling with a code
Up Next
MAKE CROSS THREAD METHOD CALLS USING INVOKE METHOD OF THE CONTROL
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
Membership not found