dispose

Dispose of a pictureBox image without losing the pictureBox

北城余情 提交于 2019-12-02 01:35:07
I am writing a program that will play a slideshow (among other things). The slideshow is controlled by a backgroundWorker, and is set to a while(true) loop so it will constantly play images. My problem is I'm not sure how to dispose of the old images so they don't take up memory (after a while the program throws an "Out of memory exception). If I call horPicBox.Image.Dispose() then it won't let me use the pictureBox at all after that. Is there a way to release the old image from memory?? If I look at the diagnostic tools in VS, the memory goes up each time the image changes ... Note:

Dispose on user controls, really meant to edit the .designer.cs file?

无人久伴 提交于 2019-12-02 01:24:37
问题 For a user control with internal data structures that must be disposed, is the correct place to add that code to the Dispose method in the .designer.cs file, or is there an event or something we're meant to use instead? Edit : This is a winforms user control. 回答1: If you're talking about WinForms I usually take one of two approaches to solve this problem. Approach 1 Open the Form.Designer.cs file. Inside the generated dispose method I add a call to DisposeCore. I then go back to Form.cs and

Exception in lazy loading (Entity Framework)

对着背影说爱祢 提交于 2019-12-02 01:13:23
I use Entity Framework in my project. The issue is well known but supposed solutions (eg. this and this ) doesn't work for me. /// <summary> /// Returns complete list of lecturers from DB. /// </summary> public IEnumerable<Lecturer> GetAllLecturers() { IList<Lecturer> query; using (var dbb = new AcademicTimetableDbContext()) { query = (from b in dbb.Lecturers select b).ToList(); } Debug.WriteLine(query[0].AcademicDegree); // Exception (***) return query; } Exception (***): The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. public

Using - what happens to my stream?

隐身守侯 提交于 2019-12-01 22:24:46
问题 Maybe it is a trival question, but it's bothering me. And don't shout laud if it is a duplicate - I tried to search, but there are so many questions regarding using that it was hard for me to find the answer. I've a code like this: using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication()) using (StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("example.txt", FileMode.Create, ISF))) writeFile.WriteLine("Example"); And my questions are: What

Dispose on user controls, really meant to edit the .designer.cs file?

你离开我真会死。 提交于 2019-12-01 21:41:15
For a user control with internal data structures that must be disposed, is the correct place to add that code to the Dispose method in the .designer.cs file, or is there an event or something we're meant to use instead? Edit : This is a winforms user control. If you're talking about WinForms I usually take one of two approaches to solve this problem. Approach 1 Open the Form.Designer.cs file. Inside the generated dispose method I add a call to DisposeCore. I then go back to Form.cs and add a DisposeCore method that will now be called during dispose. I add all of my dispose logic into this

Dispose on nested Disposable items?

荒凉一梦 提交于 2019-12-01 21:40:43
问题 I wanted to know if there are any conventions regarding disposal of disposable items nested inside another disposable item(in a property/public field, not as private members). For example, a DataSet contains DataTable(s) and a SqlCommand contains a SqlConnection. The obvious thing would be for a class to dispose of all Disposable items it owns, and leave the rest. Does there exist such a convention? If it does, how does .NET libraries determine who owns what? How can I find out whether nested

Is closing/disposing an SqlDataReader needed if you are already closing the SqlConnection?

筅森魡賤 提交于 2019-12-01 21:03:56
I noticed This question , but my question is a bit more specific. Is there any advantage to using using (SqlConnection conn = new SqlConnection(conStr)) { using (SqlCommand command = new SqlCommand()) { // dostuff } } instead of using (SqlConnection conn = new SqlConnection(conStr)) { SqlCommand command = new SqlCommand(); // dostuff } Obviously it does matter if you plan to run more than one command with the same connection, since closing an SqlDataReader is more efficient than closing and reopening a connection (calling conn.Close();conn.Open(); will also free up the connection). I see many

SqlDataAdapter with using keyword

偶尔善良 提交于 2019-12-01 20:25:48
问题 Is this the following code healthy? Or I don't need to use the using keyword as the SqlDataAdapter will handle closing the connection? public static DataSet Fetch(string sp, SqlParameter [] prm) { using (SqlConnection con = new SqlConnection(ConStr)) { using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = sp; cmd.Parameters.AddRange(prm); using (SqlDataAdapter dta = new SqlDataAdapter(cmd)) { DataSet dst = new DataSet(); dta.Fill(dst);

SqlDataAdapter with using keyword

大城市里の小女人 提交于 2019-12-01 19:14:11
Is this the following code healthy? Or I don't need to use the using keyword as the SqlDataAdapter will handle closing the connection? public static DataSet Fetch(string sp, SqlParameter [] prm) { using (SqlConnection con = new SqlConnection(ConStr)) { using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = sp; cmd.Parameters.AddRange(prm); using (SqlDataAdapter dta = new SqlDataAdapter(cmd)) { DataSet dst = new DataSet(); dta.Fill(dst); return dst; } } } } @MarkGravell I need a suggestions here, I am really looking to use DataReader ,

How can I ensure that I dispose of an object in my singleton before the application closes?

血红的双手。 提交于 2019-12-01 19:02:37
I'm using WatiN for some automated tests and what I found was that creating an IE instance for every test was not scalable. The creation and shutdown time of each IE instance was eating me alive: [TestMethod] public void Verify_Some_Useful_Thing() { using (var browser = new IE()) { browser.GoTo("/someurl"); // etc.. // some assert() statements } } However, the using statement did prove useful in that I can always ensure that my IE instance would have its dispose() method called which would close the IE window. Anyway, I created a singleton which maintained a single IE instance which all my