碰巧我试图每秒打印数千个字符串,但是我发现我的应用程序受到影响,因为Console.WriteLine(""); 使应用程序变慢得多,是否有任何方法可以对其进行优化?
我正在使用多线程在每个IP地址中,都会实时打印报告,即 http://i.imgur.com/3PII3hi.png 访问打印服务器的所有IP地址.它们大约是每秒10,000
Console.WriteLine(" Client [" + IP + "] are logged");
记录应该使用文件而不是控制台进行:
private void writeToLogFile(string pathToLogFile)
{
File.AppendAllText(pathToLogFile, "Client [" + IP + "] are logged");
}
您也想将其放在try / catch块中.
It happens that I'm trying to print thousands of strings per second, but I see that my application is affected because Console.WriteLine (""); makes the application much slower, is there any way to optimize it?
I'm working with multi threads In each IP address a report is printed in real time http://i.imgur.com/3PII3hi.png all IP addresses that access the print server. They are approximately 10,000 per second
Console.WriteLine(" Client [" + IP + "] are logged");
Logging should be done with a file, not the console:
private void writeToLogFile(string pathToLogFile)
{
File.AppendAllText(pathToLogFile, "Client [" + IP + "] are logged");
}
Also you want to put that in a try/catch block.
本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文