dispose

Multithreading exception and Dispose. Why Dispose didn't call?

旧巷老猫 提交于 2019-12-21 20:22:13
问题 'using' statement guaranteed that for the object will be called Dispose method. In this example this is not happening. And finalizer method didn't call too. Why all this? And how I can change code for guaranteed disposing of my objects when exceptions on other threads can happens? class Program { static void Main(string[] args) { Thread th1 = new Thread(ThreadOne); Thread th2 = new Thread(ThreadTwo); th1.Start(); th2.Start(); th1.Join(); th2.Join(); } static void ThreadOne() { using

Interesting event “Dispose” behaviour

百般思念 提交于 2019-12-21 20:10:06
问题 I have noticed interesting behaviour in our .NET WinForms app. We have an mdi form that has many mdi children added. These child forms listen to a "broadcast" event which is in essence a call to refresh itsself. The event is declared in a base class and the listening events added in the child forms. I've noticed that even when these child forms are closed, the events are still being hit, if the event is not explicitly removed in the Dispose() method. What is the reasoning behind this? Surely

How do I implement the dispose pattern in c# when wrapping an Interop COM Object?

China☆狼群 提交于 2019-12-21 17:06:54
问题 My class contains an object from Interop and calls a method on it which causes it to alloc stuff. It also exposes a method to free that stuff, so I expect I should call this in Dispose(): class MyClass : IDisposable { private DllName.ComClassName comInstance; void SomeMethod() { comInstance = new DllName.ComClassName(); comInstance.AllocStuff(); } public void Dispose() { comInstance.FreeThatStuff(); } } Now, I should expand all that to follow the Dispose pattern. I have no other disposable or

Ninject and DataContext disposal

为君一笑 提交于 2019-12-21 06:55:13
问题 I'm using Ninject to retrieve my DataContext from the kernel and I was wondering if Ninject automatically disposes the DataContext, or how he handles the dispose() behaviour. From own experiences I know disposing the datacontext is pretty important and that whenever you create a direct object of the DataContext (as in: new DataContext()) you should use a using() block. My question thus is: When im retrieving my DataContext from the kernel, should I still have to use a using() block? Or does

Ninject and DataContext disposal

℡╲_俬逩灬. 提交于 2019-12-21 06:53:18
问题 I'm using Ninject to retrieve my DataContext from the kernel and I was wondering if Ninject automatically disposes the DataContext, or how he handles the dispose() behaviour. From own experiences I know disposing the datacontext is pretty important and that whenever you create a direct object of the DataContext (as in: new DataContext()) you should use a using() block. My question thus is: When im retrieving my DataContext from the kernel, should I still have to use a using() block? Or does

When should I manually dispose of controls? How do I know if a control implements IDisposable?

筅森魡賤 提交于 2019-12-21 06:26:13
问题 In a previous question about ridding the system tray of an old NotifyIcon I was told that I should Dispose anything that implements IDisposable. Sounds like good practise to me however as a newbie it raises more questions :-) How do I know if a control implements IDisposable? Should I build a class that attempts to dispose everything on all my forms in the formclosed event? Something like this?(psuedocode): foreach(control cont in form) { try{cont.Dispose()} catch{} } If not, then how do I

Cross Method Dispose Patterns in SharePoint

天涯浪子 提交于 2019-12-21 05:46:13
问题 I've written a class that does various modification to the contents of a SharePoint site. Inside that class, I've implemented a lazy resolved property private SPWeb rootSite { get { if ( _site == null ) { SPSite site = new SPSite( _url ); _site = site.OpenWeb(); } return _site; } } Both the SPSite and the SPWeb need to be disposed, and according to the Best Practices document this situation is called a Cross Method Dispose Pattern... only they don't give any actual suggestion on how to

In Java, how to check that AutoCloseable.close() has been called?

五迷三道 提交于 2019-12-20 09:48:47
问题 I am authoring a java library. Some of the classes that are meant to be used by library users, hold native system resources (over JNI). I'd like to ensure that the user "disposes" these objects, as they are heavy, and in a testsuite they may cause leakage between testcases (for example, I need to ensure TearDown will dispose). For this purpose I made the Java classes implement AutoCloseable, but this doesn't seem to suffice, or I'm not using it correctly: I don't see how to use try-with

C# Not Disposing controls like I told it to

爱⌒轻易说出口 提交于 2019-12-20 05:25:30
问题 I have a Panel control. And inside the panel users can add combobox's, textbox's labels etc and drag them around and stuff, and there's a Delete button on my form where if they click it, it will delete all controls inside that panel. BUT this code: foreach( Control control in panel.Controls ) { control.Dispose(); } ... Does not work properly. It doesn't always Dispose of ALL the controls inside the panel. Sometimes it gets rid of most of them, sometimes it only gets rid of one or two.

java swing program not closing after dispose is called on last window

一世执手 提交于 2019-12-20 04:54:15
问题 Preface: This is the first real swing program I have done. I have a swing program, where one JButton is supposed to exit the program. That button triggers this.dispose();. When i click this JButton, it does make the window completely go away, but looking at the debugger, the program itself is still running. My main method only consists of: public static void main (String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new StartupGui().setVisible(true); } }); }