idisposable

XmlReader and IDisposable

Perhaps my eyes are fooling me, but how is it that in .NET 2.0, XmlReader implements Dispose but does not have a Dispose() method? I see it has Dispose(bool), but not a parameterless overload. ...

Do we need to close a C# BinaryWriter or BinaryReader in a using block?

Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here } Do we need to close the BinaryWriter? If not, why? ...

In an IDisposable pattern should a base class allow derived classes to share its disposed flag?

I am currently working on fixing a c# codebase which does not have a good pattern of Dispose usage. It is a large codebase, it is a resource demanding codebase and it uses many custom unmanaged c++ libraries at the low level. I have a good understanding of the dispose pattern. I have spent some time understanding what I believe to be ...

Can Visual Studio warn me when I forget to dispose an IDisposable object?

Can Visual Studio 2008 be configured to give me a warning when I forget to dispose an object that implements IDisposable? ...

How do I dispose an IDisposable object if the using statement throws an exception?

How can I make sure in the following code snippet that IDataReader is disposed of if ExecuteReader throws an exception? using (IDataReader rdr = cmd.ExecuteReader()) { // use it } It makes sense to me that the using syntatic sugar does not call Dispose (since there is no instance to call it on). However, how can I be sure that the...

Am I implementing IDisposable correctly?

This class uses a StreamWriter and therefore implements IDisposable. public class Foo : IDisposable { private StreamWriter _Writer; public Foo (String path) { // here happens something along the lines of: FileStream fileWrite = File.Open (path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); _Writer = new Stream...

Is the HttpContext.Current disposed even if an exception is thrown?

The reason I ask is because the HttpContext.Current.Items collection seems like it would be a good place to put IDisposable objects such as a DataContext so that a Repository might access it transparently without having to to inject any dependencies related to a specific ORM technology into the Repository. This would also allow the repos...

Standard Collection for IDisposable objects

I've got a bunch of IDisposable objects in a lookup table (plain old Dictionary<>, right now), but to simplify the code and avoid error's I'm looking for a collection class which "owns" the items it holds, and to avoid reinventing the wheel - does such a class already exist? The specification should be that: - The collection must be di...

TcpClient and NetworkStream dispose problem.

I'm using this piece of code to process a connection to a server and read data from the client using(var client = _listener.EndAcceptTcpClient(ar)) { var clientStream = client.GetStream(); // Get the request message Messages.ReceiveMessage(clientStream, msg => ProcessRequest(msg, clientStream)); } Now, the Rec...

Should Closeable be used as the Java equivalent for .NET's IDisposable?

The Closeable interface introduced in Java 1.5 is tightly tied to streams, and even has an exception specifier for IOException. This suggests that it should only be used for streams or other IO related activities, rather than general purpose cleanup logic. Certainly the description for the close() method would make absolutely no sense o...

Does ASP.Net call Dispose on the Page/Controls in a page, or must I do this?

Given that the Control class implements IDisposable, I would think that ASP.Net is at least capable of triggering a Dispose cascade as the Page finishes it's life-cycle on the way out the door to the browser? Simple question: Is this the case, or must I do this? ...

Where to dispose IDisposable members of an ASP.net page?

What is the best practice to dispose IDisposable members of an ASP.net page? Should I, ... use the Page_Unload(object sender, EventArgs e) event override the void Dispose() method of the Control class something else ... ?? ...

close, dispose, finalize, GC, Idisposable,.... have you got a clear description of them ?

hi all i am completely confused about close, dispose, finalize, GC, Idisposable. Oh, could you please send me a clear description of them? ...

Why is FxCop raising the error "Types that own disposable fields should be disposable" on a class with no disposable fields?

I have a LINQ object with an additional method added to it. The class has no disposable properties or methods, but FxCop is raising the error "Types that own disposable fields should be disposable" and referencing that class. I've reduced the code this far and still receive the error: partial class WikiPage { public PagePermission...

How do I convince my colleagues not to implement IDisposable on everything?

I work on a project where there is a huge number of objects being instanced by a few classes that stay in memory for the lifetime of the application. There are a lot of memory leaks being caused with OutOfMemoryExceptions being thrown every now and again. It seems like after the instantiated objects ago out of scope, they are not being g...

Why won't the GC automatically dispose my class's members?

When I build the following C++/CLI code in VS2008, a code analysis warning CA1001 is displayed. ref class A { public: A() { m_hwnd = new HWND; } ~A() { this->!A(); } protected: !A() { delete m_hwnd; } HWND* m_hwnd; }; ref class B { public: B() { m_a = gcnew A(); } protected: A^ m_a; }; warning: CA1...

What happens to waiting threads if I call WaitHandle.Dispose()?

I have two ManualResetEvents, which I use to pass control back and forth between two threads. Essentially a coroutine. Because the coroutine holds disposable objects (ManualResetEvents are wait handles), it should implement disposable. Also, it should dispose those ManualResetEvents when it is disposed. But, because only one thread runs...

When does a using-statement box its argument, when it's a struct?

I have some questions about the following code: using System; namespace ConsoleApplication2 { public struct Disposable : IDisposable { public void Dispose() { } } class Program { static void Main(string[] args) { using (Test()) { } } static Disposable Test() ...

Error: Do not override object.Finalize. Instead, provide a destructor

Getting the above error in following code. How to rectify it. Thanks. Please look for protected override void Finalize() { Dispose(false); } in the below code. using Microsoft.Win32; using System.Runtime.InteropServices; public class Kiosk : IDisposable { #region "IDisposable" // Implementing IDisposable since it...

IDisposable chain

If I implement a object with IDisposable, should all objects that own that object implement it as well, even if they have no other resources to release? ...