DataSet and DataTable both implement IDisposable, so, by conventional best practices, I should call their Dispose() methods.
However, from what I've read so far, DataSet and DataTable don't actually have any unmanaged resources, so Dispose() doesn't actually do much.
Plus, I can't just use using(DataSet myDataSet...) because DataSet ha...
I have an sqlConnection manager class like so:
public class SQLConn {
public string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
private SqlConnection sqlConn;
public SqlConnection Connection()
{
sqlConn = new SqlConnection(connStr);
return sqlConn;
}
public void Open(...
"File and Font are examples of managed types that access unmanaged resources (in this case file handles and device contexts). There are many other kinds of unmanaged resources and class library types that encapsulate them. All such types must implement the IDisposable interface. As a rule, when you use an IDisposable object, you should ...
What are your opinions on how disposable objects are implemented in .Net? And how do you solve the repetitiveness of implementing IDisposable classes?
I feel that IDisposable types are not the first-class citizens that they should've been. Too much is left to the mercy of the developer.
Specifically, I wonder if there should'nt have be...
Hello;
I am trying to adapt a class to work with just finished that I am not able to solve the problem.
My question is how to identify the handle to close / / CloseHandle (handle).
My problem is that I am not able to adapt the following code.
for (Int32 i = 0; i < temp_items.Count; i++)
{
string conj_itens = temp...
I was curious to see how the SingleOrFallback method was implemented in MoreLinq and discovered something I hadn't seen before:
public static T SingleOrFallback<T>(this IEnumerable<T> source, Func<T> fallback)
{
source.ThrowIfNull("source");
fallback.ThrowIfNull("fallback");
using (IEnumerator<T> iterator...
Is it legit to have your ASP.NET MVC ViewResult class implement IDisposable? My custom view result has a stream member that I want to guarantee is closed once it has been streamed back to the client. Does ASP.NET MVC honor IDiposable on ViewResult implementations?
thanks!
...
I have this object PreloadClient which implements IDisposable, I want to dispose it, but after the asynchronous methods finish their call... which is not happening
private void Preload(SlideHandler slide)
{
using(PreloadClient client = new PreloadClient())
{
client.PreloadCompleted +...
I have a 'context' object that ties itself to HttpContext.Items via a static Current property. This object can be used directly, through expression builders and controls, all being part of the same library.
The issue I'm coming across is that I want to dispose of it's managed resources (WCF clients) when a request ends without using an...
I'm using a SessionObject which is stored inside a database.
The SessionObject is wrapped inside SessionObjecWrapper which implements IDisposable.
The SessionObjectWrapper is then placed in HttpContext.Current.Session.
On session expiration, does ASP.NET "dispose" (or lets the GC do just that) of any object inside the session?
And on a...
I'm finally wrapping my head around IoC and DI in C#, and am struggling with some of the edges. I'm using the Unity container, but I think this question applies more broadly.
Using an IoC container to dispense instances that implement IDisposable freaks me out! How are you supposed to know if you should Dispose()? The instance migh...
As an example:
using (Brushes.Black)
{
...
}
is not a good idea, because it is static. The next time your app goes to use Brushes.Black, you'll have problems, because it has been disposed.
Now, if you're only using Brushes.Black, then it's probably ok to not dispose it, because you're only leaving one unmanaged resource (hopefully!) ...
Supposing I start off with the synchronous version:
using(var svc = new ServiceObject()) {
var result = svc.DoSomething();
// do stuff with result
}
I wind up with
var svc = new ServiceObject();
svc.BeginDoSomething(async => {
var result = svc.EndDoSomething(async);
svc.Dispose();
// do stuff with result
},nu...
I'm trying to make sure that my understanding of IDisposable is correct and there's something I'm still not quite sure on.
IDisposable seems to serve two purpose.
To provide a convention to "shut down" a managed object on demand.
To provide a convention to free "unmanaged resources" held by a managed object.
My confusion comes from ...
I have a base class that owns a managed disposable resource (.NET PerformanceCounter). I understand about implementing IDisposable on the class so that I can explicitly call Dispose on the resource. From the examples I have seen, people typically use a private boolean member variable "disposed" and set it to true inside of Dispose. La...
Recently, I was researching some tricky bugs about object not disposed.
I found some pattern in code. It is reported that some m_foo is not disposed, while it seems all instances of SomeClass has been disposed.
public class SomeClass: IDisposable
{
void Dispose()
{
if (m_foo != null)
{
m_foo.Dispose();
...
I was wondering if there was some sort of cheat sheet for which objects go well with the using statement... SQLConnection, MemoryStream, etc.
Taking it one step further, it would be great to even show the other "pieces of the puzzle", like how you should actually call connection.Close() before the closing using statement bracket.
Anyth...
I have a class bMainframe that manages the connections to 4 different mainframes. It allows for the same underlying unmanaged library to be opened in specific ways and more than one mainframe to be connected to at a time. Each library has its own disposal code for the unmanaged mainframe connection resource. The wrapper also has code t...
Suppose I have the following:
using(var ctx = DataContextFactory.Create(0))
{ ... Some code ... }
Why not just do the following and lose a couple of curly braces?:
var ctx = DataContextFactory.Create(0);
ctx.Dispose();
Thanks for the advice!
...
in c#, i am deserializing an object of a type that implements IDisposable with the following statement (for illustration only).
XmlSerializer s = new XmlSerializer(typeof(MyDisposable))
MyDisposable o = (MyDispoable)s.Deserialize(filepath);
afaik, the serializer tries to construct the object using the default ctor and assigning all pu...