简体   繁体   English

我应该在SitkaSoapServiceClient上使用“使用”吗?

[英]Should I use “using” on my SitkaSoapServiceClient?

(This relates to Microsoft's SitkaSoapService, in the service reference at https://database.windows.net/soap/v1/ ) (这与Microsoft的SitkaSoapService有关,位于https://database.windows.net/soap/v1/的服务参考中)

I'm using SitkaSoapServiceClient to access my SQL Data Services database by SOAP. 我正在使用SitkaSoapServiceClient通过SOAP访问我的SQL数据服务数据库。

Should I use a "using" statement every time I use this proxy class? 每次使用此代理类时,都应该使用“ using”语句吗? Or does it do its own connection handling in a safe way internally? 还是在内部以安全的方式进行自己的连接处理?

Ie do I need to say: 即我需要说:

using (SitkaSoapServiceClient proxy = GetProxy())
    proxy.Update(scope, entity);

... or is it safe to say: ...还是可以安全地说:

GetProxy().Update(scope, entity);

[where GetProxy() returns a SitkaSoapServiceClient object.] [其中GetProxy()返回SitkaSoapServiceClient对象。]

Does the proxy class code compile when wrapped in a using statement? 包裹在using语句中的代理类代码是否可以编译? If so, it implements IDisposable and I'd use it. 如果是这样,它将实现IDisposable ,我将使用它。

EDIT: calling Dispose() should incur little overhead if it does nothing, and if the designer of the class decides at a later date to allocate unmanaged resources you will be protected from a leak. 编辑:如果不执行任何操作,则调用Dispose()应该不会产生太大的开销,并且如果类的设计者在以后决定分配非托管资源,则可以防止泄漏。

当类实现IDisposable时,应始终使用using ,因为类的作者告诉您它包含一些应释放的资源。

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

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