Do I need to close a .NET service reference client when I'm done using it

后端 未结 3 1441
耶瑟儿~
耶瑟儿~ 2021-02-01 21:05

I\'m trying to find out if it is neccessary to close a .net service reference client when you are done using it. Almost all of the examples that I have come across on the net d

3条回答
  •  一生所求
    2021-02-01 21:49

    Best practice is, if the class implements IDisposable, call Dispose() in a finally clause, or wrap it with using () { }

    Edit
    Following the @casperOne comment below, it seems WCF clients should be treated more cautiously. I didn't know that, and am a little unsettled by it, with using() having served me well thus far.

提交回复
热议问题