How to create a multi-threaded application in c#?
Multi-threading allows an application to run multiple operations concurrently for better performance.
Example:
using System.Threading;
Thread newThread = new Thread(new ThreadStart(DoWork));
newThread.Start();
void DoWork()
{
Console.WriteLine("Work is being done on another thread.");
}
Solution:
The ThreadPool
provides a pool of threads that can be used to execute tasks, post work items, and process asynchronous I/O:
ThreadPool.QueueUserWorkItem((o) =>
{
Console.WriteLine("Work is being done on a thread from the thread pool.");
});