I need to test a client server application. I have server running on some port and need to create around 2000 clients connecting the server. For this i am trying to create 2000 threads in c# application using following code
class Program
{
/// <summary>
/// Sample client code that makes gRPC calls to the server.
/// </summary>
public static void Main(string[] args)
{
for (int i = 0; i <= 2000; i++)
{
CalThread cThread = new CalThread(i);
} // Exception Raised Here
}
}
class CalThread
{
public CalThread(int clientID)
{
Thread thread = new Thread(() => getDataFromServer(clientID));
thread.Start();
}
public void getDataFromServer(int clientID)
{
try
{
//Channel channel = new Channel("192.168.0.123:50051", ChannelCredentials.Insecure);
while (true)
{
//Some code to connect to server and fetch data
Thread.Sleep(15000);
}
}
catch (Exception ex)
{
Thread.Sleep(15000);
Console.WriteLine(ex.Message);
}
}
}
Here exception occur System.OutOfmemory
in for loop of Main method
However i have checked Application consume only 110 MB
memory when this exception raised ?
Why c# not let me creating threads in numbers.. ?
I have also tried Thread Pool
but not working ...