$_GET 内存不足?
我正在创建一个多线程 random.org
数字获取器来实现到我的 c# IRC 机器人中。我遇到的问题是,它使用了相当大的内存占用。我认为它是 WebClient
类。我不喜欢它仅使用 ~5,000K
内存来连接到 URL、读取第一行并输出数字。
有没有更轻松的方法?
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());
}
}
}
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());
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WebRequest 就可以了。
这看起来很复杂,但代码还是相当简单明了。
内存消耗必须比 WebClient 低得多。
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.