dispose

The dispose of an OpenFileDialog in C#?

北城以北 提交于 2019-12-11 07:54:13
问题 I have searched throughout entire Stack Overflow, but I couldn't find an answer to the following: When I'm using my OpenFileDialog, the files I open get blocked for use out of my program until I close my program. So if I open an image, I am not allowed to replace that image in my Windows Explorer anymore. I think this is a problem with disposing my OpenFileDialog, but I'm not sure how to solve it... My code: using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Title = "Open Image"; ofd

Objects need to be disposed in a specific order: is this a code smell?

点点圈 提交于 2019-12-11 07:36:58
问题 The context I'm working with a Winforms application (.NET 3.5 SP1) which has the concept of workspaces, which can contain n number of panels. Each panel (derives from Panel ) has view: .-----------------------. |Workspace | |.--------. .--------. | ||Panel1 | |Panel2 | | ||.-----. | |.-----. | | |||View1| | ||View2| | | ||'-----' | |'-----' | | |'--------' '--------' | '-----------------------' All panels get added to the this.Controls collection of the Workspace class (which derives from an

Problem with MEF - ExportFactory<T> - call Dispose method

蓝咒 提交于 2019-12-11 04:41:27
问题 If possible call dispose method on object which is created with ExportFactory? Factory is here: public interface IViewModelsControler { IChatViewModel CreatChatViewModel(); } [Export(typeof(IViewModelsControler))] public class ViewModelsControler:IViewModelsControler { [Import] public ExportFactory<IChatViewModel> ChatViewFactory { get; set; } public IChatViewModel CreatChatViewModel() { return ChatViewFactory.CreateExport().Value; } } Creation of object: var chatScreen = ViewModelControler

Properly disposing of a DbConnection

南笙酒味 提交于 2019-12-11 04:06:25
问题 I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way to setup this class for a using statement? I have implemented IDisposible, but I'm not sure when and where I should be calling Connection.Close() or Connection.Dispose(). When I simply call Connection.Dispose() in my own Dispose() method, I'll sometimes get a SocketException from my DbConnection object. I assume this is because old connections are being left open, but there's no details attached the to

Login dialog window won't dispose completely

偶尔善良 提交于 2019-12-11 03:25:01
问题 I've got a dialog window for logging in a user to a main program in Java. I've recently discovered, however, that if the user clicks the "Cancel" button or the window's native Close button, the program still runs, even if the login window itself has been disposed of. I have to force quit it. My instincts tell me that it has to do with the LoginService that is created as part of creating a JXLoginPane . Please have a look at my (well-documented) code below and give me your thoughts: package

How should I correctly dispose of an object?

你离开我真会死。 提交于 2019-12-11 02:37:28
问题 I frequently use the following code (or alike) to dispose of objects: SqlCommand vCmd = null; try { // CODE } catch(Exception ex) { /* EXCEPTION HANDLE */ } finally { if (vCmd != null) { vCmd.Dispose(); vCmd = null; } } Is this the best way to release objects and dispose of objects? I'm using the VS analytics and give me a warning about redundancies. But I always do it this way... 回答1: Here is an example from MSDN: private static void ReadOrderData(string connectionString) { string

Why use GC.SuppressFinalize() when there is no Finalizer?

本秂侑毒 提交于 2019-12-11 00:47:45
问题 As the question states, I just wanted to know, because I've been asked and I don't have a clue, is there any reason for this whatsoever? 回答1: When a class does not define a Finalizer (destructor), a call to SuppressFinalize() on an instance of that class has no effect. When you see it, it usually is a left-over of the full Disposable implementation. Just remove it or ignore it. 回答2: The reason might be to prevent potential error if someone adds a finalizer later on and forgets to add GC

Disposing a static brush

你离开我真会死。 提交于 2019-12-10 21:37:56
问题 I'm writing a biorhythm app. To test it i have a form with a Button and a PictureBox. When I click on the button i do myPictureBox.Image = GetBiorhythm2(); Which runs ok for the first time, but on the second click it causes the following exception: System.ArgumentException: Parameter is not valid. at System.Drawing.Graphics.CheckErrorStatus at System.Drawing.Graphics.FillEllipse at Larifari.Biorhythm.Biorhythm.GetBiorhythm2 in c:\delo\Horoskop\Biorhythm.cs:line 157 at Larifari.test

c# object.Dispose() or object = null

穿精又带淫゛_ 提交于 2019-12-10 18:58:51
问题 Hi I have an object has is Disposable and I would like to know what is better: this.object.Dispose(); or this.object = null; or this.object.Dispose(); this.object = null; 回答1: Dispose is better, even more better approach would be to use the object inside the using block and let the framework dispose it. For: this.object.Dispose(); vs this.object = null; Setting the object to null may result in leaving out un-managed resources un-disposed. The whole object of having IDisposable is to make sure

Java Garbage Collection and Graphics dispose method

走远了吗. 提交于 2019-12-10 18:51:07
问题 I am creating a game (a Snake Clone) as a hobby. I was looking at the dispose method from the Graphics class in the Java API. When I comment out the dispose method, My animation works the same way just fine with or without it. In the Java API, the dispose method does this- releases system resources that the graphics context is using. Doesn't the Java garbage collection manage the memory of the program similar to what the dispose is doing? Should I keep the dispose method? The API was not much