什么"获得处置倒闭"这里的意思?
为什么以下code样品中确实ReSharper的警告我获得处置倒闭:
Why does Resharper warn me about "access to disposed closure" in the following code sample:
using (SqlCommand command = new SqlCommand())
{
command.Parameters.Add("@temp", SqlDbType.VarChar);
Action<string> action = str =>
{
command.Parameters["@temp"].Value = string.Empty;
};
}
我不使用语句外使用代理...如何解决这一问题?
I don't use delegate outside using
statement... How to fix this?
您正在引用命令
在动作
,您可以使用动作
在别的地方,然后在使用
和引用
到布置命令
。
You are referencing command
in action
, you can use action
in somewhere else then in using
and reference
to disposed command
.
ReSharper的是告诉你,你可以访问到位于封闭,因为使用的动作外使用将导致。避免使用一次性的对象,这样的,当然它会抛出的NullReferenceException
,但它可以是很难找到真正的问题。
Resharper is telling you that you can access to disposed closure, because using action outside using will cause that. Avoid using disposable object like that, of course it will throw NullReferenceException
, but it can be difficult to find the real problem.