Top "Dispose" questions

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources

Try/Finally block vs calling dispose?

Is there any difference between these two code samples and if not, why does using exist? StreamWriter writer; try { writer = …

c# try-catch dispose using streamwriter
"Object can be disposed of more than once" error

When I run code analysis on the following chunk of code I get this message: Object 'stream' can be disposed …

c# dispose
Declare IDisposable for the class or interface?

Starting from the follwing situation: public interface ISample { } public class SampleA : ISample { // has some (unmanaged) resources that needs to be …

c# .net dispose idisposable
Dispose method in web api 2 web service

I am coding an MVC 5 internet application with a web api 2 web service. Do I need a dispose method for …

asp.net-mvc-5 asp.net-web-api2 dispose dbcontext repository-design
Should a .Net/C# object call Dispose() on itself?

Below is some sample code written by a colleague. This seems obviously wrong to me but I wanted to check. …

c# .net web-services dispose idisposable
How to dispose resources with dependency injection

I'm using StructureMap to resolve references to my repository class. My repository interface implements IDisposable, e.g. public interface IMyRepository : …

entity-framework dependency-injection structuremap dispose
C# disposable objects

Are there some advices about how I should deal with the IDisposable object sequences? For example, I have a method …

c# collections dispose disposable
WPF - AvalonDock - Closing Document

I use AvalonDock with MVVM in a WPF project. When I hit the "X" (Close button of the tab) my …

c# wpf mvvm dispose docking
Do I need to call Close() on a ManualResetEvent?

I've been reading up on .NET Threading and was working on some code that uses a ManualResetEvent. I have found …

c# multithreading dispose waithandle resource-leak
Is closing/disposing an SqlDataReader needed if you are already closing the SqlConnection?

I noticed This question, but my question is a bit more specific. Is there any advantage to using using (SqlConnection …

c# sql dispose sqldatareader sqlconnection