I’m creating a multi-threaded random.org number getter to implement into my c# IRC bot. The issue I have is, it uses a moderately big memory footprint. I think it’s the WebClient class. I dislike how it uses ~5,000K memory just for connecting to the url, and reading the first line and outputting the number.
Is there a lighter approach to this?
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 4; i++)
{
Thread More = new Thread(GetRandomNum);
More.Start();
}
}
public static void GetRandomNum()
{
string number;
for (int i = 0; i < 100; i++)
{
using (WebClient client = new WebClient())
{
number = client.DownloadString("http://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new");
}
Console.WriteLine(number.Trim());
}
}
}
WebRequest will do the trick.
This looks very complicated, still the code is rather simple and straightforward.
Memory consumption must be much lower than with WebClient.