friendly way to dispose of objects

As part of our Visual Studio 2010 (primarly C# 4.0) development standards, we have Code Analysis turned on. As I am reviewing recently submitted code for a new project, I am seeing a ton of CA2000 : Microsoft.Reliability: In method 'XYZ', object 'ABC' is not disposed along all exception paths. Call System.IDisposable.Dispose on object 'ABC' before all references to it

友好的方式来处理物体

作为Visual Studio 2010(主要是C#4.0)开发标准的一部分,我们开启了代码分析。 在我审查最近为新项目提交的代码时,我看到了很多 CA2000:Microsoft.Reliability:在'XYZ'方法中,对象'ABC'不是沿着所有异常路径处理的。 调用System.IDisposable.Dispose对象'ABC'之前,所有对它的引用超出范围。 警告。 问题是,我没有做任何事情似乎可以消除警告 - 我花了几个小时在网上冲浪,并尽我所能地

Disposing method which returns Timer

I have a method which returns System.Timers.Timer and then I use it along the code. But MS Code Analysis gives a warning: CA2000: Dispose objects before losing scope Is it possible to manually Dispose Timer and therefore not to spot such a message? Thank you! 由于System.Timers.Timer暗示IDisposable ,因此可以将您的方法调用包装在using语句中以确保Dispose被调用。 using(var timer = myClass.TimerMe

处理返回Timer的方法

我有一个方法返回System.Timers.Timer,然后沿代码使用它。 但MS代码分析给出了一个警告:CA2000:在丢失范围之前处理对象是否可以手动Dispose Timer并因此不发现这样的消息? 谢谢! 由于System.Timers.Timer暗示IDisposable ,因此可以将您的方法调用包装在using语句中以确保Dispose被调用。 using(var timer = myClass.TimerMethod()) { // Do the work here } System.Timers.Timer实现IDisposable所以把它放在里面usi

Incorrect elapse time for System.Timers.Timer

Possible Duplicate: System.Timer elapsed event seems to fire late for short intervals in .Net I use System.Timers.Timer in my windows service. Interval set to 60000 ms, but every next elapse, timer interval increases on some ms..Here example of log: 2011-09-05 00:00:37,177 [80] INFO - timer_Elapsed; 2011-09-05 00:01:37,187 [8] INFO - timer_Elapsed; 2011-09-05 01:24:38,279 [71] INFO -

System.Timers.Timer的过去时间不正确

可能重复: System.Timer流逝的事件似乎在.Net的短时间间隔内发生延迟 我在我的Windows服务中使用System.Timers.Timer。 间隔设置为60000毫秒,但每隔一段时间,计时器间隔都会增加一些毫秒。以下是日志示例: 2011-09-05 00:00:37,177 [80] INFO - timer_Elapsed; 2011-09-05 00:01:37,187 [8] INFO - timer_Elapsed; 2011-09-05 01:24:38,279 [71] INFO - timer_Elapsed; 但是,我需要在37秒内流逝计时器,例如

'using' statement vs 'try finally'

I've got a bunch of properties which I am going to use read/write locks on. I can implement them either with a try finally or a using clause. In the try finally I would acquire the lock before the try , and release in the finally . In the using clause, I would create a class which acquires the lock in its constructor, and releases in its Dispose method. I'm using read/write locks in

'使用'语句与'最后尝试'

我有一堆属性,我将使用读/写锁。 我可以用一个实现它们try finally或using条款。 在try finally的try finally我会在try之前获得锁定,并在finally释放。 在using子句中,我将创建一个在其构造函数中获取锁的类,并在Dispose方法中释放它。 我在很多地方都使用读/写锁,所以我一直在寻找比try finally更简洁的方法。 我有兴趣听到一些关于为什么不推荐一种方式或为什么可能比另一种更好的想法。 方法1( try finally )

block generates code analysis warning CA2000

If I use object initializers in using-block I get Code Analysis warning about not disposing the object properly: CA2000 : Microsoft.Reliability : In method 'ReCaptcha.CreateReCaptcha(this HtmlHelper, string, string)', object '<>g__initLocal0' is not disposed along all exception paths. Call System.IDisposable.Dispose on object '<>g__initLocal0' before all ref

块生成代码分析警告CA2000

如果我在using块中使用对象初始值设定项,我会得到代码分析警告,提示不要正确处理对象: CA2000:Microsoft.Reliability:在'ReCaptcha.CreateReCaptcha(this HtmlHelper,string,string)'方法中,对象'<> g__initLocal0'不会沿着所有异常路径放置。 调用System.IDisposable.Dispose在对象'<> g__initLocal0'之前,所有对它的引用超出范围。 代码如下: using (var control

Cache that guarantees single creation of cached item

I want create a cache so that when an item doesn't exist, only one person who requested that item spends the time generating it, and others that request it at the same time will simply block until the result is cached by the first person. Here is a description of that scenario: Thread 1 comes in and requests the cached data for DateA Thread 1 sees that it isn't in the cache and start

确保单个创建缓存项目的缓存

我想要创建一个缓存,以便当一个项目不存在时,只有一个请求该项目的人花费时间来产生它,而另一些人同时请求它将被阻塞,直到结果被第一个人缓存为止。 以下是该场景的描述: 线程1进来并请求为DateA缓存的数据 线程1发现它不在缓存中并开始生成信息的相对较长的过程 线程2进入一个看到,目前正在生成的信息,等待某种锁 线程3也进来,看到信息正在生成,等待某种锁 线程4进来并请求已经在缓存中的不同密钥的数据,

C Snippets for Algebra in Finite Prime Fields

I need to solve polynomials in finite prime fields on 16-bit CPUs. I have seen people using the fields GF((2^16)+1), GF((2^16)-15) , and GF((2^32)-5) . I guess these choices stem from the fact that there are several optimizations. However, apart from using "mod" I do not know any further optimizations. I would really appreciate if someone pointed me to a good resource, gave me code

C代数在有限主素场中的片段

我需要在16位CPU上求解有限素数域中的多项式。 我看到有人使用GF((2^16)+1), GF((2^16)-15)和GF((2^32)-5) 。 我想这些选择源于有几个优化的事实。 但是,除了使用“mod”之外,我不知道还有哪些优化。 如果有人给我指出一个好的资源,给我代码片段,或者解释为什么人们使用那些奇怪的素数而不是GF((2^16)-1)我会非常感激。 编辑:GF(%(2 ^ 16)+1)中的%模免模: uint32_t mod_0x10001(uint32_t divident) { uint16_t

C library for linear algebra

Please, give me some tips for a HIGH PERFORMANCE C library for linear algebra (matrix algebra, eigenvalues, eigenvectors etc.). Can be both open-source or closed-source. CLAPACK (f2c'ed version of LAPACK) GSL - GNU Scientific Library EDIT Thanks to comments from osgx: CLAPACK is the library which uder the hood uses very high-performance BLAS library, as do other libraries, like ATLAS

用于线性代数的C库

请给我一些有关线性代数(矩阵代数,特征值,特征向量等)的HIGH PERFORMANCE C库的提示。 既可以是开源的,也可以是封闭的。 CLAPACK(LAPACK的f2c版本) GSL - GNU科学图书馆 编辑感谢来自osgx的评论: CLAPACK是引擎盖使用非常高性能的BLAS库的库,就像ATLAS等其他库一样。 GSL是一个独立的C库,并不像基于BLAS的任何C库。 然而它的表现仍然相当不错(虽然不是非常好),并且经常使用; 主要是因为它的便携性。

base.Show() throwing InvalidOperationException

I am having an issue with base.Show() throwing an InvalidOperationException. There are a couple of issues with this: The error is shown in vs2012 only when I show "Common Language Runtime Exceptions" in the Debug -> Exceptions menu, but not if I run it without that. When running the program outside of vs2012, a messagebox shows showing the error with the stack trace shown at the

base.Show()抛出InvalidOperationException

我遇到了base.Show()抛出InvalidOperationException的问题。 这有几个问题: 只有当我在Debug - > Exceptions菜单中显示“Common Language Runtime Exceptions”时,该错误才会显示在vs2012中,但如果我没有运行它,则不会显示该错误。 当在vs2012之外运行程序时,消息框会显示错误,并显示此帖子底部显示的堆栈跟踪。 我试图研究在base.Show()上抛出的InvalidOperationException异常,但是在找到与base.Show()相

InvalidOperationException on webservice call with C# client and Java server side

My issues is similar to C# error executing soap client method but not exact. I want to pose a different question. On the Java server side I have a webservice with several methods. Here are 2 examples (mostly want to show the annotations here): @WebResult(name = "result") @WebMethod public TheResult method1(string x, string y) throws Exception { TheResult result = new TheResult();

使用C#客户端和Java服务器端调用webservice时的InvalidOperationException

我的问题类似于执行soap客户端方法的C#错误,但不是确切的。 我想提出一个不同的问题。 在Java服务器端,我有几个方法的web服务。 这里有两个例子(主要是想在这里显示注释): @WebResult(name = "result") @WebMethod public TheResult method1(string x, string y) throws Exception { TheResult result = new TheResult(); // continue with code, not important return result; } @