Re: Filestreams

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



For now I can just leave the stream open and let it dispose of
itself at the end of all things.

I wouldn't trust this approach; firstly, objects *never" dispose
themselves; they may get finalized by the GC, but that is not (quite)
the same thing. In fact, finalizers aren't fully guaranteed to run at
all, let alone at a predictable time. My advice: find a point in your
program where you know you are preparing to exit; explicitely Close()
and Dispose() the stream/writer, presumably by a static Close() method
on the Log class. The other option is to look for existing logging
solutions; they may do everything you need (and more) and abstract
away the complexities, including (possibly) tricks like queueing
writes in a producer/consumer pattern to avoid being IO-bound (just
blocked while enqueing).

In the threaded scenario, yes: you will need locking.

Marc


.



Relevant Pages

  • Re: Problem with C# not calling MC++ destrcutor
    ... You should deal with other resources using the dispose pattern in C#. ... At the next garbage collection they will be placed in the queue of object to be finalized, and a background process will call their finalizers eventually. ... If you implement IDisposable, it will make the memory management much more efficient. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: garbage collection of open resources
    ... > It does, there's just no guarantee. ... If finalizers take too long or create ... not calling Dispose() on a disposable object is a bug in the ... I just wanted to point out that resource leakage ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with C# not calling MC++ destrcutor
    ... finalizers (or call them destructors) don't call finalizers on instance ... IDisposable interface and from its Dispose() method, ... up the resources used by the object. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How critical is it to call Dispose()
    ... If you dispose them explicitly, ... it overkill? ... you should not introduce IDisposable interfaces and ... finalizers everywhere (which is what many people seem to think when they see ...
    (microsoft.public.dotnet.framework)
  • Re: BBC programme re: re-cyclling computers
    ... Delete (Wipe & Overwrite) Data from a Hard disk. ... who you buy things from & the Councils who you expect to dispose ... Yeah but I like a personal recommendation or suggestion;-) ... It has nothing to do with whether or not you "trust" them!!! ...
    (uk.people.silversurfers)