Coding Global Background
Coding Global

MultiThreader in cs

Archived 2 years ago
❤️3
2 messages
0 members
Created 3 years ago
Updated 3 years ago
Open in Discord
L
lunarian
Here
using System;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        Thread[] threads = new Thread[10000];

        for(int i = 0; i < threads.Length; i++)
        {
            try
            {
                threads[i] = new Thread(() =>
                {
                    Console.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId} : {i}");
                });
            }

            catch(OutOfMemoryException ex)
            {
                Console.WriteLine($"Out Of Usable Memory {ex}");
            }
        }

        foreach(Thread thread in threads)
        {
            thread.Start();
        }
    }
}

Replies (2)