Re: properly disposing of filestream

Tech-Archive recommends: Fix windows errors by optimizing your registry



Bob wrote:
Oh well, I guess I will redo this with using. Thanks for all your
input. Michael, do you think this would work if I ran as standalone
from exe instead of from Visual Studio?


I don't understand your remarks about "using".

As long as you make sure you actually call the Dispose method when you're done with your object, it should be fine. It should not matter *how* Dispose was called.

Seeing the code that uses your object would perhaps give us a clue, as would more explanation of how you're treating the object.

I suspect, however, that you're not calling Dispose and you trust GC to do it, which it won't.

Also, as remarked by others, GC.Collect() is typically not necessary and you should instead have a really good reason for using it.

--
Lasse Vågsæther Karlsen
mailto:lasse@xxxxxxxxxxx
.



Relevant Pages

  • RE: Wrapping Word.Application object with an IDisposable class?
    ... Word process is not closed in Dispose method when the application is tested ... in Visual Studio debug mode. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.languages.vb)
  • Re: The process cannot access the file (in Windows2003 only)
    ... closecalls disposefor a StreamReader/StreamWriter. ... As early as Visual Studio 2005, VB.NET has the same "Using" statement as the C# "using": ... That said, you are already calling Closeon the reader and writer, which is equivalent to calling Dispose(). ...
    (microsoft.public.dotnet.framework)
  • Method not found: Dispose System.Data.Common.DbTransaction.
    ... I received the exception: ... "Method not found: Dispose System.Data.Common.DbTransaction." ... when I execute a Transaction.Commit; ... I'm using Visual Studio 2005 RC ...
    (microsoft.public.dotnet.framework.compactframework)
  • Method not found: Dispose System.Data.Common.DbTransaction.
    ... I received the exception: ... "Method not found: Dispose System.Data.Common.DbTransaction." ... when I execute a Transaction.Commit; ... I'm using Visual Studio 2005 RC ...
    (microsoft.public.pocketpc.developer)