dispose

Bitmap and picturebox cause out of memory exception

拟墨画扇 提交于 2019-12-12 02:15:17
问题 I am trying to create an application that shows the online trains in picturebox . but my application spends a lot of memory and sometimes i got the Out of memory exception and sometimes my trains Disappears from the picturebox . To draw online train first time i draw the map of trains (lines ,stations ,...) on picturebox with size x=A and y=b after that i create another picturebox with the same size and put the second picturebox on first picturebox using this code: pictureBoxonlineTrain

Difference between Class level variable and method for CA2000 Warning

為{幸葍}努か 提交于 2019-12-12 02:08:41
问题 I am working on a Web Api for a SPA app using .net. I get CA2000 warnings when i use instantiate an object within a method. But when I declare the same object at the class level, the CA2000 warnings disappear. From below, example 1 gives the CA2000 warning while example 2 does not. Why? Example 1- public class CodeGenAPIController : ApiResponseController { NextGenCodeGen.CodeGenerator getEndPoint(TokenManager.TokenData tokenData, int BranchId) { NextGenCodeGen.CodeGenerator ret = null; lock

Why must I use Dispose()?

≡放荡痞女 提交于 2019-12-12 01:54:24
问题 Here is my code: public void InsertData() { using (SqlConnection connection = new SqlConnection(DBHelper.ConnectionString)) { using (SqlCommand command = new SqlCommand("Some Simple Insert Query", connection)) { connection.Open(); command.ExecuteNonQuery(); } } } But I found this code sample: public void InsertData() { SqlConnection connection = new SqlConnection(DBHelper.ConnectionString); connection.Open(); SqlCommand command = new SqlCommand("Some Simple Insert Query", connection); command

Windows Form Fonts Questions Part 2

人走茶凉 提交于 2019-12-11 18:36:01
问题 Continue to my previous question (link) What if I want to assign the font of a new user control to its creator's font. Should I do this a): newControl = new MyControl(...); ... newControl.Font = this.Font; or this b)? newControl = new MyControl(...); ... newControl.Font = (Font)this.Font.Clone(); If answer is a), what will happen to the new user control's font if the creator's font get disposed (for example, a window closed by user)? Thanks, Gilbert 回答1: If you are trying to enforce a

Why is Cleaner action not invoked?

蹲街弑〆低调 提交于 2019-12-11 17:36:29
问题 This is a follow-up question from this one. Specifically I'm trying to verify correct use of an API which involves calling close() on Java objects holding heavy native resources over JNI. To re-iterate from that question, this is needed in both tests and production, tests because resources leak from one testcase to another and in production because, well, native resources should just be disposed in controlled manner. The code (all such Java objects that I want disposed would extend JPeer):

How to dispose a FixedDocument

≡放荡痞女 提交于 2019-12-11 16:05:00
问题 In an application I create a FixedDocument as preview of my print. This preview is refreshed whenever the user changes some data by creating a new FixedDocument and replacing the old one used by the documentviewer. Problem is: the FixedDocument contains a lot of resources, some of them of type Image, created from ImageSources from resources. The program is eating up memory and runs out of GDI handles soon. My question: how do I dispose the FixedDocument so all the content is disposed properly

picture is used by another process (layoutpanel)

你。 提交于 2019-12-11 16:04:54
问题 So i am filling a float layout panel with images, with this code: private void FillPanel(string sql) { panel.Controls.Clear(); SQLiteConnection dbConnect = new SQLiteConnection("Data Source=" + dbFullPath + ";Version=3;"); dbConnect.Open(); SQLiteCommand runQuery = new SQLiteCommand(sql, dbConnect); SQLiteDataReader reader = runQuery.ExecuteReader(); while (reader.Read()) { PictureBox pB = new PictureBox(); pB.Image = Image.FromFile(reader["imgPath"].ToString()); pB.Size = new Size(100, 100);

Wpf managed resources cleanup

◇◆丶佛笑我妖孽 提交于 2019-12-11 13:38:33
问题 I'm trying to find a good way of cleaning up unmanaged resources that my custom controls may generate. The scenario is in which the parent window opens a child window that has a custom control with unmanaged resources (see code below). These resources need to be cleaned up when the CustomControl is no longer in use, i.e when the tree it is within is unloaded (i.e the child window closes), or it is removed from a tree (i.e it itself is unloaded) Method 1 : Unloaded event This gets triggered

When and where to call the RemoveHandler in VB.NET?

瘦欲@ 提交于 2019-12-11 12:56:45
问题 I am working to a VB.NET windows forms projet in .NET 1.1. And I have this type of architecture, very simplified. Public MustInherit Class BaseTestLogic Private _TimerPoll As Timer Public Sub New(ByVal sym As SymbolFileMng, ByVal cfg As LampTestConfig, ByVal daas As DaasManager, ByVal mcf As Elux.Wg.Lpd.MCFs.VMCF) AddHandler _TimerPoll.Tick, AddressOf TimerPoll_Tick End Sub End Class Public Class SpecificTestLogic Inherits BaseTestLogic End Class Depending of the type of test I am doing I

About Async Tasks and Disposal

夙愿已清 提交于 2019-12-11 10:33:04
问题 In my MainWindow I have a button that can be used to open a Process (native OpenProcess call) and perform some checks on it's memory, but the method called on Click is asynchronous: <Button Content="Attach" Click="OnClickAttach"/> private async void OnClickAttach(Object sender, RoutedEventArgs e) { AttachmentResult result = await m_ViewModel.Attach(); switch (result) // Different MessageBox depending on the result. } Now, let's see the ViewModel portion of code... // MemoryProcess class is