Search Results

Search found 958 results on 39 pages for 'dispose'.

Page 2/39 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Will this class cause memory leaks, and does it need a dispose method? (asp.net vb)

    - by Phil
    Here is the class to export a gridview to an excel sheet: Imports System Imports System.Data Imports System.Configuration Imports System.IO Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Namespace ExcelExport Public NotInheritable Class GVExportUtil Private Sub New() End Sub Public Shared Sub Export(ByVal fileName As String, ByVal gv As GridView) HttpContext.Current.Response.Clear() HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fileName)) HttpContext.Current.Response.ContentType = "application/ms-excel" Dim sw As StringWriter = New StringWriter Dim htw As HtmlTextWriter = New HtmlTextWriter(sw) Dim table As Table = New Table table.GridLines = GridLines.Vertical If (Not (gv.HeaderRow) Is Nothing) Then GVExportUtil.PrepareControlForExport(gv.HeaderRow) table.Rows.Add(gv.HeaderRow) End If For Each row As GridViewRow In gv.Rows GVExportUtil.PrepareControlForExport(row) table.Rows.Add(row) Next If (Not (gv.FooterRow) Is Nothing) Then GVExportUtil.PrepareControlForExport(gv.FooterRow) table.Rows.Add(gv.FooterRow) End If table.RenderControl(htw) HttpContext.Current.Response.Write(sw.ToString) HttpContext.Current.Response.End() End Sub Private Shared Sub PrepareControlForExport(ByVal control As Control) Dim i As Integer = 0 Do While (i < control.Controls.Count) Dim current As Control = control.Controls(i) If (TypeOf current Is LinkButton) Then control.Controls.Remove(current) control.Controls.AddAt(i, New LiteralControl(CType(current, LinkButton).Text)) ElseIf (TypeOf current Is ImageButton) Then control.Controls.Remove(current) control.Controls.AddAt(i, New LiteralControl(CType(current, ImageButton).AlternateText)) ElseIf (TypeOf current Is HyperLink) Then control.Controls.Remove(current) control.Controls.AddAt(i, New LiteralControl(CType(current, HyperLink).Text)) ElseIf (TypeOf current Is DropDownList) Then control.Controls.Remove(current) control.Controls.AddAt(i, New LiteralControl(CType(current, DropDownList).SelectedItem.Text)) ElseIf (TypeOf current Is CheckBox) Then control.Controls.Remove(current) control.Controls.AddAt(i, New LiteralControl(CType(current, CheckBox).Checked)) End If If current.HasControls Then GVExportUtil.PrepareControlForExport(current) End If i = (i + 1) Loop End Sub End Class End Namespace Will this class cause memory leaks? And does anything here need to be disposed of? The code is working but I am getting frequent crashes of the app pool when it is in use. Thanks.

    Read the article

  • Dispose, when is it called?

    - by Snake
    Consider the following code: namespace DisposeTest { using System; class Program { static void Main(string[] args) { Console.WriteLine("Calling Test"); Test(); Console.WriteLine("Call to Test done"); } static void Test() { DisposeImplementation di = new DisposeImplementation(); } } internal class DisposeImplementation : IDisposable { ~DisposeImplementation() { Console.WriteLine("~ in DisposeImplementation instance called"); } public void Dispose() { Console.WriteLine("Dispose in DisposeImplementation instance called"); } } } The Dispose just never get's called, even if I put a wait loop after the Test(); invocation. So that quite sucks. I want to write a class that is straightforward and very easy to use, to make sure that every possible resource is cleaned up. I don't want to put that responsibilty to the user of my class. Possible solution: use using, or call Dispose myself(basicly the same). Can I force the user to use a using? Or can I force the dispose to be called? Calling GC.Collect(); after Test(); doesn't work either. Putting di to null doesn't invoke Dispose either. The Deconstructor DOES work, so the object get's deconstructed when it exits Test()

    Read the article

  • Proper way to Dispose of a BackGroundWorker

    - by galford13x
    Would this be a proper way to dispose of a BackGroundWorker? I'm not sure if it is necesary to remove the events before calling .Dispose(). Also is calling .Dispose() inside the RunWorkerCompleted delegate ok to do? public void RunProcessAsync(DateTime dumpDate) { BackgroundWorker worker = new BackgroundWorker(); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerAsync(dumpDate); } void worker_DoWork(object sender, DoWorkEventArgs e) { // Do Work here } void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; worker.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); worker.DoWork -= new DoWorkEventHandler(worker_DoWork); worker.Dispose(); }

    Read the article

  • How to dispose NHibernate ISession in an ASP.NET MVC App

    - by Joe Young
    I have NHibernate hooked up in my asp.net mvc app. Everything works fine, if I DON'T dispose the ISession. I have read however that you should dispose, but when I do, I get random "Session is closed" exceptions. I am injecting the ISession into my other objects with Windsor. Here is my current NHModule: public class NHibernateHttpModule : IHttpModule { public void Init(HttpApplication context) { context.BeginRequest += context_BeginRequest; context.EndRequest += context_EndRequest; } static void context_EndRequest(object sender, EventArgs e) { CurrentSessionContext.Unbind(MvcApplication.SessionFactory); } static void context_BeginRequest(object sender, EventArgs e) { CurrentSessionContext.Bind(MvcApplication.SessionFactory.OpenSession()); } public void Dispose() { // do nothing } } Registering the ISession: container .Register(Component.For<ISession>() .UsingFactoryMethod(() => MvcApplication.SessionFactory.GetCurrentSession()).LifeStyle.Transient); The error happens when I tack the Dispose on the unbind in the module. Since I keep getting the session is closed error I assume this is not the correct way to do this, so what is the correct way? Thanks, Joe

    Read the article

  • Implementing Dispose on a class derived from Stream

    - by AnthonyWJones
    I'm building a class that derives from Stream to wrap a COM IStream. However I've come across an issue where I need to release the COM IStream deteministically. Ok so that's easy just use Marshal.ReleaseComObject in the Dispose method. However I'm not sure its that simple. The Stream base class already has an protected virtual method Dispose(boolean). Here is my first idea:- ~ComStreamWrapper() { if (!_Disposed) { iop.Marshal.FreeCoTaskMem(_Int64Ptr); iop.Marshal.ReleaseComObject(_IStream); } } protected override void Dispose(bool disposing) { base.Dispose(disposing); if (!_Disposed) { if (disposing) { iop.Marshal.FreeCoTaskMem(_Int64Ptr); iop.Marshal.ReleaseComObject(_IStream); } _Disposed = true; } } You'll notice there isn't an implementation of Dispose() itself. I'm currently making the asssumption that the existing implementation on Stream does what I need it to. That is calling Diposing(true) and GC.SuppressFinalize. Is this assumption faulty? Have I missed something? Is there a better approach? You see more of the basic class in this answer to an ealier question.

    Read the article

  • C# Dispose() -clarification

    - by nettguy
    When i call object.Dispose(); Will CLR immediately destroy the object from memory or mark the object for removal in it's next cycle?. We are calling GC.SuppressFinalize() immediately after Dispose(),Does it mean ,"Don't collect the object again for dispose,because it is already submitted to displose". Actually which generation is responsible for destruction ,i guess generation 2.

    Read the article

  • How do you prevent IDisposable from spreading to all your classes?

    - by GrahamS
    Start with these simple classes... Let's say I have a simple set of classes like this: class Bus { Driver busDriver = new Driver(); } class Driver { Shoe[] shoes = { new Shoe(), new Shoe() }; } class Shoe { Shoelace lace = new Shoelace(); } class Shoelace { bool tied = false; } A Bus has a Driver, the Driver has two Shoes, each Shoe has a Shoelace. All very silly. Add an IDisposable object to Shoelace Later I decide that some operation on the Shoelace could be multi-threaded, so I add an EventWaitHandle for the threads to communicate with. So Shoelace now looks like this: class Shoelace { private AutoResetEvent waitHandle = new AutoResetEvent(false); bool tied = false; // ... other stuff .. } Implement IDisposable on Shoelace Buit now FxCop will complain: "Implement IDisposable on 'Shoelace' because it creates members of the following IDisposable types: 'EventWaitHandle'." Okay, I implement IDisposable on Shoelace and my neat little class becomes this horrible mess: class Shoelace : IDisposable { private AutoResetEvent waitHandle = new AutoResetEvent(false); bool tied = false; private bool disposed = false; public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } ~Shoelace() { Dispose(false); } protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (waitHandle != null) { waitHandle.Close(); waitHandle = null; } } // No unmanaged resources to release otherwise they'd go here. } disposed = true; } } Or (as pointed out by commenters) since Shoelace itself has no unmanaged resources, I might use the simpler dispose implementation without needing the Dispose(bool) and Destructor: class Shoelace : IDisposable { private AutoResetEvent waitHandle = new AutoResetEvent(false); bool tied = false; public void Dispose() { if (waitHandle != null) { waitHandle.Close(); waitHandle = null; } GC.SuppressFinalize(this); } } Watch in horror as IDisposable spreads Right that's that fixed. But now FxCop will complain that Shoe creates a Shoelace, so Shoe must be IDisposable too. And Driver creates Shoe so Driver must be IDisposable. and Bus creates Driver so Bus must be IDisposable and so on. Suddenly my small change to Shoelace is causing me a lot of work and my boss is wondering why I need to checkout Bus to make a change to Shoelace. The Question How do you prevent this spread of IDisposable, but still ensure that your unmanaged objects are properly disposed?

    Read the article

  • Unity to dispose of object

    - by Johan Levin
    Is there a way to make Unit dispose property-injected objects as part of the Teardown? The background is that I am working on an application that uses ASP.NET MVC 2, Unity and WCF. We have written our own MVC controller factory that uses unity to instantiate the controller and WCF proxies are injected using the [Dependency] attribute on public properties of the controller. At the end of the page life cycle the ReleaseController method of the controller factory is called and we call IUnityContainer.Teardown(theMvcController). At that point the controller is disposed as expected but I also need to dispose the injected wcf-proxies. (Actually I need to call Close and/or Abort on them and not Dispose but that is a later problem.) I could of course override the controllers' Dispose methods and clean up the proxies there, but I don't want the controllers to have to know about the lifecycles of the injected interfaces or even that they refer to WCF proxies. If I need to write code myself for this - what would be the best extension point? I'd appreciate any pointer.

    Read the article

  • Is it important to dispose SolidBrush and Pen?

    - by Joe
    I recently came across this VerticalLabel control on CodeProject. I notice that the OnPaint method creates but doesn't dispose Pen and SolidBrush objects. Does this matter, and if so how can I demonstrate whatever problems it can cause? EDIT This isn't a question about the IDisposable pattern in general. I understand that callers should normally call Dispose on any class that implements IDisposable. What I want to know is what problems (if any) can be expected when GDI+ object are not disposed as in the above example. It's clear that, in the linked example, OnPaint may be called many times before the garbage collector kicks in, so there's the potential to run out of handles. However I suspect that GDI+ internally reuses handles in some circumstances (for example if you use a pen of a specific color from the Pens class, it is cached and reused). What I'm trying to understand is whether code like that in the linked example will be able to get away with neglecting to call Dispose. And if not, to see a sample that demonstrated what problems it can cause. I should add that I have very often (including the OnPaint documentation on MSDN) seen WinForms code samples that fail to dispose GDI+ objects.

    Read the article

  • How the dispose() method works in C#.net?

    - by Shailesh Jaiswal
    I am developing smart device application in C#. It is a window application. In that application I have created the 4 to 5 window form. I am navigating in these forms from one form to another form by using linklabel control in C#. In linklabel_Click() method which I am using to navigate I am using the code form1.show() according to need. I read that form1.show() method automatically calls the form1.dispose() method on the from1. I also read that once we dispose the form it is removed from memory & we can not call it again. But in my application no one form gets disposed. I can see all the form even after calling the form1.show() method. when I use the link to go once again to from1 it does not get disposed. Is anything wrong in my concept? I am new in C#. Please tell me how the dispose method work in above context? What is the use of dispose method. It will be better if you describe me above issue with example.

    Read the article

  • Are finalizers ever allowed to call other managed classes' methods?

    - by romkyns
    I used to be pretty sure the answer is "no", as explained in Overriding the Finalize method and Object.Finalize documentation. However, while randomly browsing through FileStream in Reflector, I found that it can actually call just such a method from a finalizer: private SafeFileHandle _handle; ~FileStream() { if (this._handle != null) { this.Dispose(false); } } protected override void Dispose(bool disposing) { try { ... } finally { if ((this._handle != null) && !this._handle.IsClosed) // <=== HERE { this._handle.Dispose(); // <=== AND HERE } [...] } } I started wondering whether this will always work due to the exact way in which it's written, and hence whether the "do not touch managed classes from finalizers" is just a guideline that can be broken given a good reason and the necessary knowledge to do it right. I dug a bit deeper and found out that the worst that can happen when the "rule" is broken is that the managed object being accessed had already been finalized, or may be getting finalized in parallel on a separate thread. So if the SafeFileHandle's finalizer didn't do anything that would cause a subsequent call to Dispose fail then the above should be fine... right? Question: so there might after all be situations in which a method on another managed class may be called reliably from a finalizer? I've always believed this to be false, but this code suggests that it's possible and that there can be good enough reasons to do it. Bonus: Observe that the SafeFileHandle will not even know it's being called from a finalizer, since this is just a normal call to Dispose(). The base class, SafeHandle, actually has two private methods, InternalDispose and InternalFinalize, and in this case InternalDispose will be called. Isn't this a problem? Why not?...

    Read the article

  • Disposing a Bitmap through its Finalizer

    - by devoured elysium
    I have a complex program in which I have to first create, then use wrappers around bitmaps and send them across a lot of different classes. The problem in the end is deciding which classes should dispose the bitmaps. Most of the time the end classes don't know if they can indeed dispose the bitmap as the same bitmap can be used in several places. Also, I can't just copy the bitmaps because this is a kind of resource intensive algorithm and doing it would be dead slow. I looked up on reflector for Image/Bitmap's implementations and they seem to use the Dispose Pattern. So, even if I don't call Dispose(), the CLR will eventually call it some other time. Is it too bad if I just let the bitmaps be as they are, and let the finalizer take care of them?

    Read the article

  • How-to dispose a waithandle correctly

    - by TomTom
    Hello, I'm doing some multi-threading and use AutoResetEvents and ManualResetEvents do control my main - loop. When "destryoing" the threads I also have to dispose these signals, that's clear. But I saw different ways how to dispose Waithandles, and I'm not sure which one is correct: Version 1 if (disposing) { this.threadExitEvent.SafeWaitHandle.Dispose(); this.threadExitEvent.Close(); this.threadExitEvent = null; .... } Version 2 if (disposing) { this.threadExitEvent.Close(); this.threadExitEvent = null; .... } Version 3 if (disposing) { this.threadExitEvent.Close(); .... }

    Read the article

  • Help me understand Dispose() implementation code from MSDN

    - by Benny
    the following code is from MSDN: Idisposable pattern protected virtual void Dispose(bool disposing) { // If you need thread safety, use a lock around these // operations, as well as in your methods that use the resource. if (!_disposed) { if (disposing) { if (_resource != null) _resource.Dispose(); Console.WriteLine("Object disposed."); } // Indicate that the instance has been disposed. _resource = null; _disposed = true; } } why the following statement: _resource = null; _disposed = true; are not enclosed by if (disposing) statement block? for me i would probably write like this: if (disposing) { if (_resource != null) { _resource.Dispose(); _resource = null; _disposed = true; } Console.WriteLine("Object disposed."); } anything wrong with my version?

    Read the article

  • How to dispose of old rack-mount servers?

    - by Nic
    I have two old rack-mount servers lying around that I want to get rid of. One is a HP DL380 G2, the other is an IBM from the same era. Both machines boot up, but I don't have any harddrives for them, or any use for them. Worse yet, both machines appear to have been dropped at some point and the rail kits are bent out of shape and can't be removed, making them unusuable in a rack environment. I'd like to recycle them or dispose of them in some kind of safe manner, but don't really know what my options are. I'm in western Canada. Any suggestions? Update: If you found this question interesting, please consider visiting StackExchange Area 51 to support the proposal for a dedicated Recycling Q&A site.

    Read the article

  • Proper way to dispose of Quartz.NET?

    - by Seth Spearman
    I am using Quartz.NET in an application. What is the proper way to dispose of Quartz.NET. Right now I am just doing if (_quartzScheduler != null) { _quartzScheduler = null; } Is that enough or should I implement a dispose or something in the jobType class? Seth

    Read the article

  • Do i need to dispose of MySqlCommand?

    - by acidzombie24
    I find it incredibly annoying to write a using statement on every one of my queries (which require its own command or write parameters.clear()) which sometimes require declaring variables outside of the using block. Its so incredibly annoying and looks much dirtier compared to the version without disposing the object. Do i need to dispose of it? what happens if i dont? I do know its good practice to dispose of an object when it has that interface.

    Read the article

  • How to dispose BackgroundWorkers the right way

    - by radbyx
    I've got a Windows Service that runs BackgroundWorker's, and I'm wondering if I'm doing the right thing when I stop my Windows Service. Is it enough to: Let the BackgroundWorker1_DoWork method complete (I have a while loop in it now, doing some tasks) Set the variable that holds the reference to the BackgroundWorker, to null Is there some kind of Dispose() method I need to call (In the same way the Timer class has Timer.Dispose();)?

    Read the article

  • How to dispose the objects created by factory pattern

    - by Ram
    Hi, I am using Factory pattern to create .NET objects of a class. I also need to make sure that all such objects should be disposed before application terminates. Where and How can I dispose the objects created by factory pattern? Shall I dispose in the class in which I am getting the objects created by factory?

    Read the article

  • C#: Does an IDisposable in a Halted Iterator Dispose?

    - by James Michael Hare
    If that sounds confusing, let me give you an example. Let's say you expose a method to read a database of products, and instead of returning a List<Product> you return an IEnumerable<Product> in iterator form (yield return). This accomplishes several good things: The IDataReader is not passed out of the Data Access Layer which prevents abstraction leak and resource leak potentials. You don't need to construct a full List<Product> in memory (which could be very big) if you just want to forward iterate once. If you only want to consume up to a certain point in the list, you won't incur the database cost of looking up the other items. This could give us an example like: 1: // a sample data access object class to do standard CRUD operations. 2: public class ProductDao 3: { 4: private DbProviderFactory _factory = SqlClientFactory.Instance 5:  6: // a method that would retrieve all available products 7: public IEnumerable<Product> GetAvailableProducts() 8: { 9: // must create the connection 10: using (var con = _factory.CreateConnection()) 11: { 12: con.ConnectionString = _productsConnectionString; 13: con.Open(); 14:  15: // create the command 16: using (var cmd = _factory.CreateCommand()) 17: { 18: cmd.Connection = con; 19: cmd.CommandText = _getAllProductsStoredProc; 20: cmd.CommandType = CommandType.StoredProcedure; 21:  22: // get a reader and pass back all results 23: using (var reader = cmd.ExecuteReader()) 24: { 25: while(reader.Read()) 26: { 27: yield return new Product 28: { 29: Name = reader["product_name"].ToString(), 30: ... 31: }; 32: } 33: } 34: } 35: } 36: } 37: } The database details themselves are irrelevant. I will say, though, that I'm a big fan of using the System.Data.Common classes instead of your provider specific counterparts directly (SqlCommand, OracleCommand, etc). This lets you mock your data sources easily in unit testing and also allows you to swap out your provider in one line of code. In fact, one of the shared components I'm most proud of implementing was our group's DatabaseUtility library that simplifies all the database access above into one line of code in a thread-safe and provider-neutral way. I went with my own flavor instead of the EL due to the fact I didn't want to force internal company consumers to use the EL if they didn't want to, and it made it easy to allow them to mock their database for unit testing by providing a MockCommand, MockConnection, etc that followed the System.Data.Common model. One of these days I'll blog on that if anyone's interested. Regardless, you often have situations like the above where you are consuming and iterating through a resource that must be closed once you are finished iterating. For the reasons stated above, I didn't want to return IDataReader (that would force them to remember to Dispose it), and I didn't want to return List<Product> (that would force them to hold all products in memory) -- but the first time I wrote this, I was worried. What if you never consume the last item and exit the loop? Are the reader, command, and connection all disposed correctly? Of course, I was 99.999999% sure the creators of C# had already thought of this and taken care of it, but inspection in Reflector was difficult due to the nature of the state machines yield return generates, so I decided to try a quick example program to verify whether or not Dispose() will be called when an iterator is broken from outside the iterator itself -- i.e. before the iterator reports there are no more items. So I wrote a quick Sequencer class with a Dispose() method and an iterator for it. Yes, it is COMPLETELY contrived: 1: // A disposable sequence of int -- yes this is completely contrived... 2: internal class Sequencer : IDisposable 3: { 4: private int _i = 0; 5: private readonly object _mutex = new object(); 6:  7: // Constructs an int sequence. 8: public Sequencer(int start) 9: { 10: _i = start; 11: } 12:  13: // Gets the next integer 14: public int GetNext() 15: { 16: lock (_mutex) 17: { 18: return _i++; 19: } 20: } 21:  22: // Dispose the sequence of integers. 23: public void Dispose() 24: { 25: // force output immediately (flush the buffer) 26: Console.WriteLine("Disposed with last sequence number of {0}!", _i); 27: Console.Out.Flush(); 28: } 29: } And then I created a generator (infinite-loop iterator) that did the using block for auto-Disposal: 1: // simply defines an extension method off of an int to start a sequence 2: public static class SequencerExtensions 3: { 4: // generates an infinite sequence starting at the specified number 5: public static IEnumerable<int> GetSequence(this int starter) 6: { 7: // note the using here, will call Dispose() when block terminated. 8: using (var seq = new Sequencer(starter)) 9: { 10: // infinite loop on this generator, means must be bounded by caller! 11: while(true) 12: { 13: yield return seq.GetNext(); 14: } 15: } 16: } 17: } This is really the same conundrum as the database problem originally posed. Here we are using iteration (yield return) over a large collection (infinite sequence of integers). If we cut the sequence short by breaking iteration, will that using block exit and hence, Dispose be called? Well, let's see: 1: // The test program class 2: public class IteratorTest 3: { 4: // The main test method. 5: public static void Main() 6: { 7: Console.WriteLine("Going to consume 10 of infinite items"); 8: Console.Out.Flush(); 9:  10: foreach(var i in 0.GetSequence()) 11: { 12: // could use TakeWhile, but wanted to output right at break... 13: if(i >= 10) 14: { 15: Console.WriteLine("Breaking now!"); 16: Console.Out.Flush(); 17: break; 18: } 19:  20: Console.WriteLine(i); 21: Console.Out.Flush(); 22: } 23:  24: Console.WriteLine("Done with loop."); 25: Console.Out.Flush(); 26: } 27: } So, what do we see? Do we see the "Disposed" message from our dispose, or did the Dispose get skipped because from an "eyeball" perspective we should be locked in that infinite generator loop? Here's the results: 1: Going to consume 10 of infinite items 2: 0 3: 1 4: 2 5: 3 6: 4 7: 5 8: 6 9: 7 10: 8 11: 9 12: Breaking now! 13: Disposed with last sequence number of 11! 14: Done with loop. Yes indeed, when we break the loop, the state machine that C# generates for yield iterate exits the iteration through the using blocks and auto-disposes the IDisposable correctly. I must admit, though, the first time I wrote one, I began to wonder and that led to this test. If you've never seen iterators before (I wrote a previous entry here) the infinite loop may throw you, but you have to keep in mind it is not a linear piece of code, that every time you hit a "yield return" it cedes control back to the state machine generated for the iterator. And this state machine, I'm happy to say, is smart enough to clean up the using blocks correctly. I suspected those wily guys and gals at Microsoft engineered it well, and I wasn't disappointed. But, I've been bitten by assumptions before, so it's good to test and see. Yes, maybe you knew it would or figured it would, but isn't it nice to know? And as those campy 80s G.I. Joe cartoon public service reminders always taught us, "Knowing is half the battle...". Technorati Tags: C#,.NET

    Read the article

  • "Collection was modified; enumeration operation may not execute." on form disposal.

    - by cyclotis04
    "Collection was modified; enumeration operation may not execute." appears to be a common error with foreach loops, but I can't figure mine out. I have two classes of forms. One is begun on startup, and a button creates new instances of the second form, and displays them. When I close the secondary forms, I get an InvalidOperationException. FirstForm.cs public partial class FirstForm : Form { SecondForm frmSecond; ... private void button1_Click(object sender, EventArgs e) { frmSecond= new SecondForm (); frmSecond.Show(); } } SecondForm.designer.cs partial class SecondForm { ... protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); // InvalidOperationException thrown here. } }

    Read the article

  • SqlCommand.Dispose() not disposing the SqlParameters in it - Memory Leak - C#.NET

    - by NLV
    Hello I've a windows forms application with MS SQL Server 2005 as the back end. I have written code in the form to call few stored procedures using SqlConnection, SqlCommand objects and i properly dispose everything. I've disposed sqlcommand object by calling oSqlCommand.Dispose() But i witnessed my application consuming huge amount of memory. I basically pass large XML files as SqlParameters. I finally decided to memory profile it using RedGate Memory profiler and i noticed that the System.Data.SqlClient.SqlParameters are not disposed. Any insights on this? Thanks NLV

    Read the article

  • How to Dispose myClass with Garbage Collecter C#

    - by Ibrahim AKGUN
    Hi, I have a class and got a method that doin so many things in memory and need to be disposed when its jobs done.But i have looked for MSDN for solution.There is an example thats not solved my problem.When my Class is instanced and run this method my memory is getting bigger and bigger.How can i Dispose it when its job done ? Here is my CODES ; class Deneme { public Deneme() { } ~Deneme() { GC.Collect(); GC.SuppressFinalize(this); } public void TestMetodu() { System.Windows.Forms.MessageBox.Show("Test"); // This is my method that doing big jobs :) } } Deneme CCCX = new Deneme(); CCCX.TestMetodu(); CCCX = null; So i cant dispose it with this.

    Read the article

  • return the variable used for using inside the using C#

    - by di3go
    Hello, I am returning the variable I am creating in a using statement inside the using statement (sounds funny): public DataTable foo () { using (DataTable properties = new DataTable()) { // do something return properties; } } Will this Dispose the properties variable?? After doing this am still getting this Warning: Warning 34 CA2000 : Microsoft.Reliability : In method 'test.test', call System.IDisposable.Dispose on object 'properties' before all references to it are out of scope. Any Ideas? Thanks

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >