C#win应用程序会降低其他应用程序和PC的速度 [英] C# win application slows down other apps and PC

查看:70
本文介绍了C#win应用程序会降低其他应用程序和PC的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 12中开发了一个C#windows应用程序。当我运行这个应用程序时,它会减慢所有其他应用程序的速度并使PC运行缓慢。我认为这需要太多的物理内存。请建议一些解决方法,以避免减慢我的PC。

以下是对开发的应用程序的介绍:

该应用程序是非常数据密集型的。该应用程序包含一个for循环,循环大约80000次,这个for循环也有一个内循环循环100000次。我将所有数据存储在列表,数组和对象中(我认为这些数据结构消耗内存)

E.X. for(i = 0; i< 80000; i ++)

{

for(j = 0; j< 10000; j ++)

{

//使用数学公式(正弦,余弦,sqr根)进行一些科学计算,并调用一些用户定义的函数

}

}



还建议如何快速启动此应用程序!!!

I have developed a C# windows application in Visual Studio 12. When I run this application, it slows down all other apps and makes PC slow., I think it takes too much of physical memory. Pls suggest some work around to avoid slowing down my PC.
Below is the introduction to application developed :
The application is very data intensive. The application contains one for loop which loops through around 80000 times and this "for loop" also have one "inner for loop" which loops through 100000 time. I store all the data in lists, arrays and objects(I think these data structures consuming memory)
E.X. for(i=0;i<80000;i++)
{
for(j=0; j<10000;j++)
{
//do some scientific calculations using mathematical formulas (sine, cos, sqr roots) and calls some user defined functions
}
}

Also suggest how to make this application fast!!!

推荐答案

如果数据密集型应用程序正在减速其他一切,然后它需要利用该CPU时间来执行其处理。但是,如果您不介意共享CPU时间,请偶尔弹出 System.Threading.Thread.Sleep(0)调用(特别是在大循环中)。这将释放CPU到其他进程和线程以便能够完成他们的工作,然后操作系统将依次授予您的程序公平份额的时间片。
If a data intensive application is slowing down everything else, then it needs to utilise that CPU time to perform its processing. If you don't mind sharing the CPU time, however, pop a System.Threading.Thread.Sleep(0) call occasionally (particularly inside big loops). That will release the CPU to other processes and threads to be able to do their stuff, and the operating system will then award your program its fair share of the time-slices in turn.


首先要做的是验证你是否真的需要嵌套循环来完成整个范围。如果你可以有一个O(m log n)而不是O(m)的算法,其中m是第一个循环的长度,n是第二个循环的长度,那么它会快得多。



要验证的第二件事是你是否真的需要同时拥有所有内存。



第三件事就是要做配置CPU使用率。 Visual Studio需要的工具。



最后要检查的是内存使用情况。同样,你可以使用一些内存分析工具,或者你可以使用任务管理器有一个粗略的想法。



如果你的内存使用量超过几百兆字节,那么如果您的计算机内存非常有限,它可能会对其他应用程序产生重大影响。



最后对于这样的大循环,您可能不得不考虑缓存问题容器的选择。
The first thing to do is to verify if you really need to have nested loops doing the whole range each. If you can have an algorithm of O(m log n) instead of O(m) where m is the length of first loop and n the length of the second loop, then it would be much faster.

The second thing to verify is if you really need to have all in memory at once.

The third thing to do is to profile CPU usage. Visual Studio have required tools for that.

The final thing to check is memory usage. Again, you can use some memory profiling tools or you can have a rough idea using task manager.

If you memory usage is more than a few hundred of megabytes, then it might be possible that it has a significant impact on other application if your computer has very limited memory.

Finally for such big loops, you might have to consider caching issues and the choice of containers.


您好,在您的代码中运行巨大的循环,这是在单线程上运行。因此要么使用多线程应用程序,要么使用Application.DoEvents()



Hi there, seems you are running huge loops inside your code which is running on single thread. So either you use a multithreading application or use Application.DoEvents()

for(i=0;i<80000;i++)
{
	for(j=0; j<10000;j++)
	{ 
		//do some scientific calculations using mathematical formulas (sine, cos, sqr roots) and calls some user defined functions 
		Application.DoEvents();
	} 
	Application.DoEvents();
} 


这篇关于C#win应用程序会降低其他应用程序和PC的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆