I use a dll and I haven't its source code. Somebody advised me to use a fonction of this dll like this :
void IDSCallback.Received(NetworkStream a)
{
using (a)
{
// Some code...
}
}
I don't understand the purpose of the using. At the end of this function, a.Dispose() is called so a is no longer usable.
So the function which called the IDSCallback.Received() can't use it anymore.
Why the using is in the function IDSCallback.Received() and not in the function which called IDSCallback.Received() ?
ashould certainly not be disposed in this method asReceiveddoes not own it.usingon objects whose lifetime you actually want to limit.Somebodyis wrong. Unless it is proper of you to close the stream as part of theReceivedmessage (e.g. as part of a "close" message or something), you shouldn't do that. For the most part, it's a bad idea to useusingon things that aren't basically local variables you've just created :)