简体   繁体   English

如何优化 Console.WriteLine ("");

[英]How can I optimize Console.WriteLine ("");

It happens that I'm trying to print thousands of strings per second, but I see that my application is affected because Console.WriteLine ("");碰巧我试图每秒打印数千个字符串,但我看到我的应用程序受到影响,因为 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.我正在使用多线程在每个 IP 地址中实时打印一份报告http://i.imgur.com/3PII3hi.png所有访问打印服务器的 IP 地址。 They are approximately 10,000 per second它们大约每秒 10,000 个

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.你也想把它放在一个 try/catch 块中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM