在没有try-catch的情况下将异常作为System.OutOfMemoryException处理 [英] handling the exception as System.OutOfMemoryException without try-catch

查看:96
本文介绍了在没有try-catch的情况下将异常作为System.OutOfMemoryException处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了创建线程数的C#应用​​程序.

经过一段时间后,创建新线程时,它将引发System.OutOfMemoryException异常.
不使用try-catch来处理此异常的任何想法吗?

还是如何增加内存空间或如何从内存中释放线程.这个东西处理得非常快?

哪个循环可以更好地处理数组(同时,对于每个数组).
如何在MYSQL C#中提高更新查询的性能还需要120-198毫秒或更短的时间
更新数据库(使用左联接和联合通过一个查询更新1000行).

可以提高MYSQL执行非查询性能的任何方法.

I have developed the C# application creating the number of threads.

After some time elapsed it throws exception as System.OutOfMemoryException when creating a new Thread.
Any idea to handle this exception.without using try - catch?

Or how to increase the space in memory or how to release the thread from memory.this thing handle very fast?

Which loop gives the better performance fro handling the array (while,for, for each).
How to increased the performance of the update query in MYSQL C# it takes 120-198 milliseconds or less also
to update the database (updating the 1000 lines through one query using left join & union).

Anything to increase the performance of the MYSQL execute non query.

推荐答案

什么在消耗您的内存?如果这些线程是大量创建的,请使用线程池或以任何其他方式限制其计数(推迟一些线程中执行的工作).如果这是您的数据库,请限制最大内存量.如果无法执行其他操作,请使用AppDomain.UnhandledException或Application.ThreadException处理程序
What is consuming your memory? If these are threads created in huge numbers, use thread pool or restrict their count in any other way (postpone some work performed in threads). If this is your database, restrict maximum amount of memory. If nothing else can be done, use AppDomain.UnhandledException or Application.ThreadException handlers


在运行时开始某个地方创建线程的整个想法令人怀疑.您有不确定或不确定的线程数吗?这是设计错误的标志.几乎所有内容都可以基于固定数量的线程进行设计.

有关正确的线程设计的一些想法,请参阅我的链接集合,该链接指向我过去关于以下主题的一些答案:
如何获取keydown事件在vb.net中的不同线程上操作 [启用禁用+多线程后控件事件不会触发 [ ^ ].

遇到OutOfMemoryЕxception时,通常已经为时已晚,无法挽救局面.并非在所有情况下都可以,但是几乎可以.您真正应该做的唯一一件事就是减少内存消耗.在许多情况下,这是很有可能的.

很难根据您的有限信息为您提供进一步的指导.您的项目应进行深入分析,并审查代码.您对如何在项目中提供更多基本信息有任何想法吗?怪怪一些特殊的建筑解决方案?还有什么吗?

—SA
The whole idea of creation of thread somewhere in the beginning of run time is a suspect. Do you have uncertain or non-deterministic number of threads? This is a sign of wrong design. Almost everything can be designed based on fixed number of threads.

For some ideas on right threading designs, please see my collection of links to some of my past answers on the topic:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

When you run into OutOfMemoryЕxception, it''s usually already too late to save the situation; not in all cases, but pretty much. The only thing you really should do is to reduce memory consumption. In many situations it is quite possible.

It''s hard to give you further directions based on your limited information. Your project should be analyzed in depth and the code reviewed. Do you have any ideas how to provide more essential information on your project? Some peculiar architectural solutions to blame? anything else?

—SA


这篇关于在没有try-catch的情况下将异常作为System.OutOfMemoryException处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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